在 print("you dont have that many cards!")
我希望 while 循环从
print("how many cards in heap no:", n, end="")
而不是打破。如何才能做到这一点?
y = []
def cardHeaps():
global cards
n = 1
while int(cards) > 0:
print("how many cards in heap no:", n, end="")
x = int(input("? "))
cards = int(cards)
if x > cards:
print("you dont have that many cards!")
break
y.append(x)
cards -= int(x)
print(cards, " cards left")
n += 1
if cards <= 0:
print("out of cards!")
break
最佳答案
您必须使用 continue
而不是 break
。
Python docs on continue
关于python - 返回到循环的顶部,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7027355/