返回循环的顶部

时间:2011-08-11 14:08:32

标签: python

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

2 个答案:

答案 0 :(得分:13)

您必须使用continue代替break

Python docs on continue

答案 1 :(得分:10)

使用continue而不是break。