diff options
author | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
---|---|---|
committer | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
commit | 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch) | |
tree | 84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chapter3PracCollate.py |
Diffstat (limited to 'Chapter3PracCollate.py')
-rw-r--r-- | Chapter3PracCollate.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Chapter3PracCollate.py b/Chapter3PracCollate.py new file mode 100644 index 0000000..0d47132 --- /dev/null +++ b/Chapter3PracCollate.py @@ -0,0 +1,23 @@ +# The Collatz Sequence + +def collatz(number): + global result + if number % 2 == 0: + print(str(number // 2)) + result = number // 2 + return result + elif number % 2 == 1: + print(str(3 * number + 1)) + result = 3 * number + 1 + return result + +print('Enter number:') +while True: + try: + number = int(input()) + except ValueError: + print('The value must be an integer!') + continue + collatz(number) + if result == 1: + break |