import os
def collatz(number):
if(number%2==0):
return number//2
else:
return number*3+1
while True:
a=int(input())
if(a!=1):
print(collatz(a))
continue
else:
break
《Python编程快速上手—让繁琐工作自动化》第3章3.11.1
最新推荐文章于 2022-04-09 20:53:39 发布
import os
def collatz(number):
if(number%2==0):
return number//2
else:
return number*3+1
while True:
a=int(input())
if(a!=1):
print(collatz(a))
continue
else:
break