c0=int(input("enter a number here"))
Question:
My code:
c01=c0%2
c02=3*c0+1
while c0!=1:
if c01==0:
print(c01)
else:
print(c02)
c0+=1
print("total number steps",)
Sample input: 16
Expected output:
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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.