Collatz 序列 (考兹特猜想)

# It is a practice.
def collatz(num):
    if num % 2 == 0 :
        return num//2
    elif num % 2 == 1:
        return 3*num + 1
    else:
        print('error')
try:
    num = int(input())
    while num!=1:
        print(collatz(num))
        num = collatz(num)
except ValueError :
    print('valueError')

你可能感兴趣的:(Collatz 序列 (考兹特猜想))