Advertisement
Guest User

joy

a guest
Feb 28th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. def main():
  2. start = eval(input("Enter starting number of the range:"))
  3. end = eval(input("Enter ending number of the range:"))
  4.  
  5. while((start < 0) or (end < 0) or (start > end)):
  6. start = eval(input("Enter starting number of the range:"))
  7. end = eval(input("Enter ending number of the range:"))
  8.  
  9. max_num = 0
  10. max_cycle = 0
  11. cycle = 0
  12. for n in range(start, end + 1, 1):
  13. print(n)
  14. max_num = n
  15. while (n != 1):
  16. if (n % 2 == 0):
  17. n = (n // 2)
  18. cycle = cycle + 1
  19. else:
  20. n = (n * 3) + 1
  21. cycle = cycle + 1
  22. if cycle >= max_cycle:
  23. max_cycle = cycle
  24. max_num = n
  25. cycle = 0
  26.  
  27. print("The number", max_num, "has the longest cycle length of", max_cycle)
  28.  
  29.  
  30. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement