beginners need to write Collatz sequences when learning Python, chapters, and then write such code themselves
< H1 > this is a code exercise about Collatz sequences < / H1 > print ("Enter number:")
def Collatz ():
try:
num = int(input())
while num !=1 :
if num %2 == 0:
num = num // 2
print(num)
elif num %2 == 1:
num = 3*num+1
print(num)
except ValueError:
print("Error! Please Enter number")
print (Collatz ())
Enter number:
5
16
8
4
2
1
None
None, appears unexpectedly in the return value above. I want to ask which point in the code caused this None, and how should it be removed?
having tried if num = = 1 sys.exit breakbreakor calling