# [Tutor] checking if a number is evan or odd

Ian Witham witham.ian at gmail.com
Tue Sep 4 04:41:57 CEST 2007

```Hi Max,

A better way to check if a number is odd or even would be to find the
remainder after it is divided by two.

for instance: 4 divided by 2 = 2 with 0 remainder
5 divided by 2 = 2 with 1 remainder
6 divided by 2 = 3 with 0 remainder
7 divided by 2 = 3 with 1 remainder

As well as the floor division operator '/', Python has another operator for
finding the remainder (or 'modulus')

On 9/4/07, max baseman <dos.fool at gmail.com> wrote:
>
> hello just a quick check in, it's about the same program i was asking
> 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
> 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
>
>
> after a few days i got this error:
>
> Traceback (most recent call last):
>    File "homework6high.py", line 11, in <module>
>      if number/2 == (number+0.0)/2:
> OverflowError: long int too large to convert to float
>
> just wondering if theirs a way to check if a larger number is even or
> odd
>
> thanks
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070904/d1c8c3bc/attachment.htm
```