Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return to the top of a loop

Tags:

python

At print("you dont have that many cards!") i want the while loop to start over from

print("how many cards in heap no:", n, end="")

instead of breaking. How can this be done?

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
like image 402
Sergei Avatar asked Nov 27 '22 12:11

Sergei


1 Answers

You have to use continue instead of break.

Python docs on continue

like image 170
Jacob Avatar answered Dec 19 '22 13:12

Jacob