mercredi 8 mai 2019

unable to continue while statement when adding in def menu into code

This is my first python code. So i apologise if the question is silly. I have created a code that does basic shopping cart calculations. The code worked fine until i added in a def main menu. I run the code and it loops back to the main menu instead of continuing to the next while statement I have.

The user comes to enter their input "do you want to add anything else to your cart" when I test the input since the main menu was added the "yes" or "no" entries automatically go back to the main menu regardless what i enter

I tired using a break after the input but that does not allow for a "yes" answer it continues to the next while statement as if the user input was "no"

I have removed the def main menu and the code works just on while if else statements with nil issues

But i would like to be able to have the main menu using def

this is the menu

def printMenu():
    print("Welcome to the Lollie Store")
    print("Please select from the following options")
    print("A: Display Lollies, Cost and Weight to go ahead with purchase")
    print("B. Quit")
    word = input("What would you like to do ? Enter A or B: ")
    return word

#this is the end of the code where the issue is occurring 

     count +=1
else:
     print()
     print("That as been added to your cart.")
    choice = input("Do you want to add any other item to your cart : ") 

while choice == 'n' 
    print()
    print("There are",count,"items in your cart")

I would like when the user enters their input "yes" or "no"
The code will either take the user back to add something else in their cart or continue to the next while statement

Aucun commentaire:

Enregistrer un commentaire