我研究循环while并执行下一个任务。
我有一定数量的糖果,我会慢慢吃掉并在屏幕上报告。
糖果一吃完,我就问自己:“我应该买更多的糖果吗?”
如果我还想吃甜的,我也会再买一些糖;如果我加了0,就意味着我已经吃饱了,退出这个循环。
无法回到循环的开头:
x_bullets = 11
end_bullets = 1
while x_bullets > end_bullets:
x_bullets -= 1
print(x_bullets)
if x_bullets == end_bullets:
print("Recharge")
ammo_recharge = int(input())
if ammo_recharge >= 1:
continue
else:
print("You are out of ammo!")
break
但
break不需要else_x_bullets另外,设置为 10 并x_bullets -= 1在使用(输出)当前值后执行会更自然作为一个选项