[Tutor] checking if a number is evan or odd

Alan Gauld alan.gauld at btinternet.com
Tue Sep 4 11:00:53 CEST 2007


Max,

> just wondering if theirs a way to check if a larger number is even 
> or
> odd

I notice this is homework so I won't give a direct answer.
But look at the mod operator '%'  - It returns the remainder
of an integer division. An even number is exactly divisible
by 2.

HTH,

Alan G.

"max baseman" <dos.fool at gmail.com> wrote

> about before ive let it sit for a few days now and i reached a 
> number
> to high to convert to a decimal by adding 0.0

Thats a terrible way to convert to a float. Just use the float 
function
(actually a type):

f = float(anInt)

But to determine if its odd/even you don't need to use floats at all.


> here's the program:
>
> count=1
> numstart=268549802
> number=0
> high=0
> a=0
> while 1==1:
>     numstart=numstart+1
>     number=numstart
>     count=1
>     while number !=1:
>         if number/2 == (number+0.0)/2:
>             number=number/2
>         else:
>             number=(number*3)+1
>         count=count+1
>     if count > a:
>         a=count
>         print numstart,":",count


Hmm, I have no idea what this is doing...

>
> thanks
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list