I\'m trying to write a Collatz program using the guidelines from a project found at the end of chapter 3 of Automate the Boring Stuff with Python. I\'m using python 3.
def collatz(number):
if number%2==0:
return number//2
elif number%2==1:
return number*3+1
step=1 #counter variable for amusement and seeing how many steps for completion.
try: #in case of ValueError
number=int(input('Enter a Number for Collatz Sequencing:'))
while collatz(number)!=1:
print(collatz(number))
number=int(collatz(number))
if collatz(number)!=1:
print('Calculating step ' + str(step) + '.')
step=step+1
else:
print ('Calculating step ' +str(step) + '.')
print('1 Has Been Reached.')
except ValueError:
print('Enter an Integer please:')