BC88 魔法数字变换
思路:
step1:输入一个数;创建一个计数器;分奇数偶数进行运算,直到n==1结束循环;打印次数;
代码如下:
n = int(input())
c = 0
while n != 1:
if n%2 == 0:
n = n/2
c += 1
else:
n = n*3 + 1
c += 1
print(c)
n = int(input())
c = 0
while n != 1:
if n%2 == 0:
n = n/2
c += 1
else:
n = n*3 + 1
c += 1
print(c)