I'm learning python and just started using automate the boring stuff to learn.
This is the code I came up for collatz sequence. I don't know if it's good because if I don't enter an integer, the program finishes and I guess it's supposed to restart the loop so I can use an integer and I don't know how to do that.
This is the code:
def collatz(number):
if number % 2 == 0:
return number // 2
elif number % 2 == 1:
return 3*number +1
print("Insert a number")
try:
number = int(input())
while number != 1:
number = collatz(number)
print (number)
except ValueError:
print ("Use an integrer")