PAT (Basic Level) Practice Python解法 1001 害死人不偿命的(3n+1)猜想 (while true/if)
hys = int(input())
num = 0
while hys!=1:
if hys%2==0:
hys = hys/2
num = num + 1
else:
hys = (hys*3+1)/2
num = num + 1
print(num)
1 也可以用while True在if走完之后判hys是否为1→break。