Advertisement
Guest User

Untitled

a guest
Mar 30th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. def collatz(numer):
  2.  
  3. if numer % 2 == 0:
  4. print(numer // 2)
  5. return numer // 2
  6.  
  7. elif numer % 2 == 1:
  8. result = 3 * numer + 1
  9. print(result)
  10. return result
  11.  
  12.  
  13. n = input("podaj liczbe: ")
  14. while n != 1:
  15. n = collatz(int(n))
  16. if n == 0:
  17. print("podales liczbe 0, podaj inna liczbe")
  18. break
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement