返回循环的顶部

2024-04-16 21:00:22 发布

您现在位置: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

Tags: noinyouifthathavemanyheap