Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I make a working if statement that repeats on if false in Python?

name = input("What is your name?\n")

menu = "Black Coffee", "Espresso", "Latte", "Cappucino","Frappuccino"

while True:
   order = input(name + ", what would you like from our menu today? Here is what we are serving.\n")
   if order == "Black Coffee":
       print("Thank you.")
   elif order == "Espresso":
        print("Thank you.")
   elif order == "Latte":
        print("Thank you.")
   elif order == "Cappucino":
        print("Thank you.")
   elif order == "Frappucino":
        print("Thank you.")
   else:
       print("play again.. etc...")

quantity = input("How many " + order + "s would you like?\n")

total = price * int(quantity)

total_time = int(quantity) * time

print("Thank you. Your total is: $" + str(total))

print("Sounds good " + name + ", we will have your " + quantity + " "+ order + " ready for you in " + str(total_time) + " min.")

I am a guy who is a beginner in Python. I have a problem with my code that when I enter for example "Latte" It will say "Thank you." and it jumps back and says "name + , what would you like from our menu today? Here is what we are serving.". I do not want that to happen, instead I want it to say the line under it (How many " + order + "s would you like?). Also, when I add the variable "menu" to my "order" variable (in the string) it says "can only concatenate str (not "tuple") to str"
I would really appreciate your help.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use the break keyword to break out of the while loop:

while True:
   order = input(name + ", what would you like from our menu today? Here is what we are serving.\n")
   if order in menu:
       print("Thank you.")
       break
   else:
       print("play again.. etc...")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading