[Tutor] cmp()

Kyle Babich kb@kb2.net
Thu, 15 Aug 2002 01:05:58 UT


On Wed, 14 Aug 2002 15:39:09 -0700 (PDT), "Danny Yoo"
<dyoo@hkn.eecs.berkeley.edu> said:
>=20
>=20
> On Wed, 14 Aug 2002, Kyle Babich wrote:
>=20
> > Ok, so based on this I tried:
> >
> > ##########
> > from sys import *
> >
> > arg1 =3D stdin.readline()[-1:]
> > arg2 =3D stdin.readline()[-1:]
> >
> > compar =3D cmp(arg1, arg2)
> >
> > if compar =3D=3D 1:
> >     print "first greater"
> > elif compar =3D=3D 0:
> >     print "equal"
> > elif compar =3D=3D -1:
> >     print "second greater"
> > else:
> >     print "error"
> > ##########
> >
> > So why no matter what I enter it returns that they are equal?
>=20
> Hi Kyle,
>=20
> Can you explain what these two lines are doing?
>=20
> > arg1 =3D stdin.readline()[-1:]
> > arg2 =3D stdin.readline()[-1:]
>=20

Taking user input, removing the \n that is put at the end of it by
default & dumping it into arg1 and arg2.

>=20
> Good luck!
Thank you
>=20
>=20

--
Kyle