Last active
April 26, 2020 15:35
-
-
Save kurzweil777/d077681fc2acbd68d7cb04d5842d2d06 to your computer and use it in GitHub Desktop.
Collate Sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collatz(number): | |
global result | |
if number % 2 == 0: | |
result = number // 2 | |
return result | |
elif number % 2 == 1: | |
result = 3 * number + 1 | |
return result | |
try: | |
users_number = int(input("Введите целое число: ")) | |
except ValueError: | |
print ("Вы ввели не целое число") | |
exit() | |
result = collatz(users_number) | |
while result != 1: | |
result_after = collatz(result) | |
print(result_after) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment