grandfathermagic

ממש קלוץ בתחת

Apr 24th, 2020
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. # Get number from user
  2. # if number is even devide by 2 till you get to 1
  3. # if number is odd multiply by 3 and add 1 - run the loop again
  4.  
  5. def kloze(user_input):
  6.     counter = 0
  7.     while user_input > 1:
  8.         if 0 == user_input % 2:
  9.             user_input = (user_input // 2)
  10.             counter += 1
  11.         else:
  12.             user_input = (user_input * 3) + 1
  13.             counter += 1
  14.     return counter
  15.  
  16. biggest_index = 0
  17. the_real_big_one = 0
  18. biggest = 0
  19. i = 1
  20. while i < 1000:
  21.     if kloze(i) > biggest:
  22.         biggest = kloze(i)
  23.         biggest_index = i
  24.  
  25.         # print(f" if we pick the number {i}  we will need  {kloze(i)}  action to get to 1")
  26.     i += 1
  27.     the_real_big_one = f"The number {biggest_index} need  {biggest} actions to get to 1 "
  28.  
  29. print(the_real_big_one)
Advertisement
Add Comment
Please, Sign In to add comment