I am trying to make a program that calculates when a number will reach zero using the Collatz sequence. Here is my code for that program:
import time
def run(z):
while z != 1:
if isEven(z) == True:
z = z/2
print z
else:
z = (3*z)+1
print z
else:
print 'Got one!'
z = z+1
print 'Trying for %d...' %(z)
time.sleep(0.1)
run(z)
def isEven(number):
return number % 2 == 0
run(z)
However, the z
never goes above 2, it only keeps printing:
Got one!
Trying for 2...
1
Got one!
Trying for 2...
1
And so on... Can anyone tell me what I am doing wrong?