Created
April 14, 2023 23:18
-
-
Save nobuh/d8ef60369a8c86d66b6bd1e890b78e51 to your computer and use it in GitHub Desktop.
コラッツ数例
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: int) -> int: | |
if number % 2 == 0: | |
return number // 2 | |
else: | |
return 3 * number + 1 | |
try: | |
number = int(input('整数を入力してください:')) | |
print(number) | |
while number > 1: | |
number = collatz(number) | |
print(number) | |
except ValueError: | |
print('不正な値です') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment