i = 10
while i>=1:
print("count down in " + str(i))
i = i - 1 #or i +=1
if i<10:
print("blasting off")
if i==0:
print("ready in " +str(i))
while i<=10:
print("starting up in " + str(i))
i +=1
count_up = 0
count_down = 10
while True:
count_up += 1
count_down -= 1
print("Count_up: ", count_up)
print("Count_down:", count_down)
if count_up == 10: # once it counts up to 10 reset to 0
count_up = 0
if count_down == 0: # once it dounts down to 0 reset to 10
count_down = 10
这将上升10,下降10 endlessley
或者,如果您只想在本例中使用1个变量i:
i = 10
while True:
print(i)
i -= 1
if i == 0:
for j in range(10):
print(i)
i += 1
i = 10
temp = True
while(True):
i = 10
while i>=1:
print("count down in " + str(i)
i -= 1
if i<10:
print("blasting off")
if i==0:
print("ready in " +str(i))
while i<=10:
print("starting up in " + str(i))
i +=1
将两个循环放在无限外循环中,例如:
这将上升10,下降10 endlessley
或者,如果您只想在本例中使用1个变量i:
在python中,有一种简单的方法可以完成无休止的循环。您可以使用while(True),它将始终为True。我希望这有帮助
相关问题 更多 >
编程相关推荐