def collatz(number): while True: if number%2==0: number=number//2 print(number) elif number%2==1 and number!=1: number=number*3+1 print(number) else: break print('enter number:') try: number=int(input()) collatz(number) except ValueError: #检测是否输入非整数 print('请输入整数:') number=int(input()) collatz(number)
效果呈现:
标签:考拉,猜想,--,collatz,number,int,print,input From: https://www.cnblogs.com/lucass/p/17120119.html