Advertisement
JumpYScriptsz

3x + 1

Oct 4th, 2021 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # made by JumpYScriptsz
  2. # SUMMARY - If num = odd, (num x 3)+1, if even num / 2
  3.  
  4. import time
  5.  
  6. # VARIABLES #
  7.  
  8. sleep = 0.01
  9.  
  10.  
  11. # OTHER VARIABLES DONT TOUCH #
  12.  
  13. x = True
  14. count = -1
  15.  
  16. # ======== main part here, DONT touch ======== #
  17. num = int(input("Enter a number: "))
  18. while x == True:
  19.     count = count + 1
  20.     time.sleep(sleep)
  21.     if (num % 2) == 0:
  22.         num = num/2
  23.         print(int(num))
  24.     elif num == 1:
  25.         print()
  26.         print("ended with",count,"numbers formed!")
  27.         x = False # change this 2 true for inf loop
  28.     else:
  29.        num = (3*num)+1
  30.        print(int(num))
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement