# 通过不断对一个整数调用这个函数,最终结果均为1
def collatz(number):
if number % 2 == 0:
number = number // 2
elif number % 2 == 1:
number = 3*number + 1
return number
try:
getNumber = int(input("烦请输入您想输入的整数:"))
while True:
getNumber = collatz(getNumber)
print(getNumber)
if getNumber == 1:
break
except Exception as e:
print("烦请输入整数,不是其他看不懂的数字")
12-23
647
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-24
173
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)