The core part of this program, it performs the operations of the Collatz sequence to the given number (parameter number).
(number: float)
| 61 | print("\nBEGIN COLLATZ SEQUENCE") |
| 62 | |
| 63 | def sequence(number: float) -> float: |
| 64 | """ |
| 65 | The core part of this program, |
| 66 | it performs the operations of |
| 67 | the Collatz sequence to the given |
| 68 | number (parameter number). |
| 69 | """ |
| 70 | modulo = number % 2 # The number modulo'd by 2 |
| 71 | if modulo == 0: # If the result is 0, |
| 72 | number = number / 2 # divide it by 2 |
| 73 | else: # Otherwise, |
| 74 | number = 3 * number + 1 # multiply by 3 and add 1 (3x + 1) |
| 75 | return number |
| 76 | |
| 77 | # Execute the sequence |
| 78 | while True: |