Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- num1 = int(input("Enter starting number of the range: "))
- num2 = int(input("Enter ending number of the range: "))
- counter = 0
- longestCycle = 0
- lcNum = 0
- temp = 0
- for i in range(num1,num2 + 1):
- temp = i
- while i > 1:
- if i % 2 == 0:
- i = i / 2
- elif i % 2 == 1:
- i = 3 * i + 1
- counter += 1
- if counter >= longestCycle:
- longestCycle = counter
- lcNum = temp
- counter = 0
- print("The number", str(lcNum), "has the longest cycle length of", str(longestCycle))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement