Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Collatz Operation
- def collatz(number):
- if number % 2 == 0: # Check for Even
- operation = number // 2
- print(operation)
- return operation
- else:
- operation = 3 * number + 1
- print(operation)
- return operation
- # Recurse Collatz
- def callCollatz():
- try:
- num = int(input("Enter an integer: \n")) # Accept User Input and Parse it to Integer Type
- while True: # Infinite Loop
- num = collatz(num) # Set the Number To the Current Return Value of Collatz Operation in Local Iteration
- if num == 1: # Break If The Collatz Sequence Ends
- break
- except ValueError:
- print("Please input an integer!")
- # Invoke Collatz
- callCollatz()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement