[Python] Breaking out of while loop

Discussão em 'Python' iniciado por Stack, Agosto 25, 2025.

  1. Stack

    Stack Membro Participativo

    shoppingList = [('Carrot',2), ('Onion',1), ('Tomato',3)]
    amountGiven = 12
    for item, price in shoppingList:

    openMenu = True
    while openMenu:
    customerPick = input('Please choose item from the shoppingList\n')

    if customerPick == 'Carrot':
    print('That would be: ${}'.format(price))
    amountGiven = amountGiven - price

    elif customerPick == 'Onion':
    print('That would be: ${}'.format(price))
    amountGiven = amountGiven -price

    elif customerPick == 'Tomato':
    print('That would be: ${}'.format(price))
    amountGiven = amountGiven - price


    I want to break out the loop after the customer chooses one of these options

    Continue reading...

Compartilhe esta Página