Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. def main():
  2. num1 = int(input("Enter starting number of the range: "))
  3. num2 = int(input("Enter ending number of the range: "))
  4. counter = 0
  5. longestCycle = 0
  6. lcNum = 0
  7. temp = 0
  8. for i in range(num1,num2 + 1):
  9. temp = i
  10. while i > 1:
  11. if i % 2 == 0:
  12. i = i / 2
  13. elif i % 2 == 1:
  14. i = 3 * i + 1
  15. counter += 1
  16. if counter >= longestCycle:
  17. longestCycle = counter
  18. lcNum = temp
  19. counter = 0
  20. print("The number", str(lcNum), "has the longest cycle length of", str(longestCycle))
  21. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement