[Tutor] Find out if a number is even or not
nik
my.mailing.lists at noos.fr
Fri Oct 15 13:15:43 CEST 2004
try using the mod operator, %
if 10%2 == 0 etc...
this returns the remainder left over from dividing the two numbers
nik
nick at javacat.f2s.com wrote:
>Hi group,
>
>Im sure this is simple to do, but Ive just been looking through the python docs
>and the archive of this mailing list and cant find what Im after.
>
>I just want to know if a number is even or not.
>
>I've had a look at the math package but that doesnt seem to have anything this
>simple in it.
>
>I thought something like
>
>
>
>>>>if 10 div 2 == 0 : print 'even'
>>>>else : print 'odd'
>>>>
>>>>
>
>but obviously that doesnt work.
>
>Sorry for such a basic question, but I really cant find out how to do this.
>
>Kind regards
>Nick.
>
>
>
>
>
>-------------------------------------------------
>Everyone should have http://www.freedom2surf.net/
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
More information about the Tutor
mailing list