Advertisement
Guest User

Collatz conjecture

a guest
Dec 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. l = input("Enter a number: ")
  2. l = int(l)
  3. i = []
  4. def collatz(n):
  5.     print(i) # <= print here
  6.     if n==1:
  7.         return i
  8.     if n%2 == 0:
  9.         n = n/2
  10.         i.append(n)
  11.         return collatz(n)
  12.     else:
  13.         n = ((n*3) + 1) / 2
  14.         i.append(n)
  15.         return collatz(n)
  16.     print(i)
  17. collatz(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement