Hello,
the main problem is that your function doesn't return any value, like mlieqo says. Also you have two points more to revise:
1- input function returns a 'char'. Then you are comparing in your loop in its first iteration a char with a int. '1' is not the same that 1. You solve it to cast the input.
2- You are not controlling negative values. Then, a -1, -5, -100... values are allowed (maybe "while n>1")
Maybe anything like this:
the main problem is that your function doesn't return any value, like mlieqo says. Also you have two points more to revise:
1- input function returns a 'char'. Then you are comparing in your loop in its first iteration a char with a int. '1' is not the same that 1. You solve it to cast the input.
2- You are not controlling negative values. Then, a -1, -5, -100... values are allowed (maybe "while n>1")
Maybe anything like this:
def collatz(number): if number % 2 == 0: result = number//2 return result else: result = 3*number + 1 return result try: n = int(input("Give me a number: ")) while n != 1: print(n) n = collatz(n) except ValueError: print('Type a number please!')... Sorry for my low English level...