grandfathermagic

ממש קלוץ בתחת

May 2nd, 2020
569
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.  
  17. biggest_index = 0
  18. the_real_big_one = 0
  19. biggest = 0
  20. i = 1
  21. while i < 1000:
  22.     if kloze(i) > biggest:
  23.         biggest = kloze(i)
  24.         biggest_index = i
  25.  
  26.         # print(f" if we pick the number {i}  we will need  {kloze(i)}  action to get to 1")
  27.     i += 1
  28.     the_real_big_one = f"The number {biggest_index} need  {biggest} actions to get to 1 "
  29.  
  30. print(the_real_big_one)
Advertisement
Add Comment
Please, Sign In to add comment