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(num):
if num % 2:
return 3 * num + 1
else:
return num // 2
while True:
try:
number = int(input('Enter a positive integer.'))
if number <= 0:
continue
break
except ValueError:
continue
while number != 1:
number = collatz(number)
print(number)