Advertisement
thekin

Python - Hailstone Sequence (REMAKE)

Jul 29th, 2020
1,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.21 KB | None | 0 0
  1. num = int(input("N: "))
  2.  
  3. seq = [num]
  4.  
  5. while num != 1:
  6.     num = num // 2 if num % 2 == 0 else num * 3 + 1
  7.    
  8.     seq.append(num)
  9.  
  10. print(", ".join(str(num) for num in seq))
  11. print("Length: {}".format(len(seq)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement