Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- start = eval(input("Enter starting number of the range:"))
- end = eval(input("Enter ending number of the range:"))
- while((start < 0) or (end < 0) or (start > end)):
- start = eval(input("Enter starting number of the range:"))
- end = eval(input("Enter ending number of the range:"))
- max_num = 0
- max_cycle = 0
- cycle = 0
- for n in range(start, end + 1, 1):
- print(n)
- max_num = n
- while (n != 1):
- if (n % 2 == 0):
- n = (n // 2)
- cycle = cycle + 1
- else:
- n = (n * 3) + 1
- cycle = cycle + 1
- if cycle >= max_cycle:
- max_cycle = cycle
- max_num = n
- cycle = 0
- print("The number", max_num, "has the longest cycle length of", max_cycle)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement