Truman, in your final code, you are now printing the results twice, first in your collatz function and then in your while loop. So now if I input f.e. number 3 output is:
Actually in this case, if statement from my comment above
Output:3
10
10
5
5
16
16
8
8
4
4
2
2
1
You should remove print from your collatz function, and probably add one more condition for printing number 1.def collatz(number): if number % 2 == 0: return number//2 else: result = 3*number + 1 return result try: n = int(input("Give me a number: ")) while n != 1: print(n) n = collatz(abs(n)) if n == 1: print(n) except ValueError: print('Type a number please!')Also one more thing to consider -> I dont think user should be able to input negative number, from what I read on wikipedia -
Quote:The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows: start with any positive integer n.
Actually in this case, if statement from my comment above
if n == 1:should be replaced with else(same result, but nicer).