Skip to content

Instantly share code, notes, and snippets.

@nobuh
Created April 14, 2023 23:18
Show Gist options
  • Save nobuh/d8ef60369a8c86d66b6bd1e890b78e51 to your computer and use it in GitHub Desktop.
Save nobuh/d8ef60369a8c86d66b6bd1e890b78e51 to your computer and use it in GitHub Desktop.
コラッツ数例
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