[英]How do I solve this problem with while loop
c0=int(input("enter a number here"))
题:
我的代码:
c01=c0%2
c02=3*c0+1
while c0!=1:
if c01==0:
print(c01)
else:
print(c02)
c0+=1
print("total number steps",)
样本输入:16
预期输出:
8
4
2
1
steps = 4
while True:
c0 = int(input("Enter a Number Here: "))
if c0 > 0:
break
else:
continue
count = 0
while c0 != 1:
if c0 % 2 == 0:
c0 = c0 / 2
print("{} ".format(int(c0)))
else:
c0 = 3 * c0 + 1
print("{} ".format(int(c0)))
count += 1
print("Steps: {}".format(count))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.