[Tutor] checking if a number is evan or odd
max baseman
dos.fool at gmail.com
Wed Sep 5 00:19:30 CEST 2007
cool thanks thats what i changed it to than just now i changed to do
something else and instead of leaving the program running for 4 or 5
days as i had been i got my answer in less than a second ^_^"
i realized that i was wasting way to much time checking every
possible answer because the number is jumping around so much so
instead i wrote a real quick program infact i wrote it in
interactive that just starts at 1 and works the problem backwards for
how ever long i tell it to :))
thanks for considering the homework, but this time you did'nt have to
worry i did the homework last week i was just doing this for fun, it
randomly asked something like "what about a number that takes 100
steps to get to 1" and i thought what about 1000 :)) now i have one
running looking for a number that takes 1000000 steps unfortunately i
dont think ill get any extra credit for doing any of this lol
here is the program sorry copying it from interactive:
>>> number=1
>>> count=1000
>>> count=0
>>> while count < 1000:
... if (number*2)%2 == 0:
... number=number*2
... else:
... number=(number-1)/3.0
... count=count+1
... print number
On Sep 4, 2007, at 3:00 AM, Alan Gauld wrote:
> 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
>>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list