I'm new to python and am trying to fix this and By defualt its running the else statment I don't understand and need help. I'm new so please dumb your answers down to my -5 iq
menu = "Baguette , Crossiant , Coffee , Tea , Cappuccino "
print(menu)
if "" > menu:
order = input("What Would you like? \n ")
amount = input("How many " order " would you like?")
print( name " Your " amount " " order " will be ready soon!\n\n\n")
price = int(4)
#converts number into intenger to do math correctly (int)
total = price * int(amount)
#turns total into string intead of intenger to prevent error in terminal
print("Thank you, your total is: $" str(total))
print("Your " amount " of " order " is ready!")
print("Please enjoy you " order "!")
print("Please come again!")
else:
#If not on menu stops running
print("Sorry Thats not on the menu")
quit()
I changed the if "" to on_menu and list the options but it didn't work, and I asked people on discord.
CodePudding user response:
menu = ["Baguette" , "Crossiant" , "Coffee" , "Tea" , "Cappuccino "]
count = 0
for item in menu:
print(str(count) " -> " str(item))
count = 1
order = int(input("\n What Would you like? \n "))
if order > len(menu) or order < 0 or order == "" or not menu[order]:
print("Sorry Thats not on the menu")
quit()
orderCount = int(input("How many " menu[order] " would you like?"))
print("Your " str(orderCount) " " menu[order] " will be ready soon!\n\n\n")
amount = int(4) * int(orderCount)
print("Thank you, your total is: $" str(amount))
print("Your " str(amount) " of " str(menu[order]) " is ready!")
print("Please enjoy you " str(menu[order]) "!")
print("Please come again!")
CodePudding user response:
Currently you are not checking the user input, you are just checking for a False statement based on what you defined. You need to check if the user input is on the menu, else quit the program.
menu = "Baguette , Crossiant , Coffee , Tea , Cappuccino "
print(menu)
name = input("What your name? \n ")
order = input("What Would you like? \n ")
if not order.lower() in menu.lower(): # checking if user input is in the menu
#If not on menu stops running
print("Sorry Thats not on the menu")
quit()
amount = input("How many " order " would you like?")
print( name " Your " amount " " order " will be ready soon!\n\n\n")
price = int(4)
#converts number into intenger to do math correctly (int)
total = price * int(amount)
#turns total into string intead of intenger to prevent error in terminal
print("Thank you, your total is: $" str(total))
print("Your " amount " of " order " is ready!")
print("Please enjoy you " order "!")
print("Please come again!")
CodePudding user response:
#input name
name = input("What is your name?\n")
#create menu
menu = "Baguette, Crossiant, Coffee, Tea and Cappuccino"
#display menu
print(menu)
#input order
order = input("What would you like?\n")
#if the order item is in the menu
if order in menu:
#input quantity
amount = input("How many " order "s would you like? ")
#display message
print( name " Your " amount " " order " will be ready soon!\n\n\n")
#setting price of all items to 4
price = 4
#calculating total
total = price * int(amount)
#turns total into string intead of intenger to prevent error in terminal
print("Thank you, your total is: $" str(total))
print("Your " amount " of " order " is ready!")
print("Please enjoy you " order "!")
print("Please come again!")
#if the item is not in menu
else:
#display message
print("Sorry Thats not on the menu")
Hope this helps! I have added the explanation as comments.
CodePudding user response:
Issue is your giving definite false value, means your comparing 0 > 1, the answer always will be false. and that's why its keep going in else.
Second logical issue is without taking order how you can say its in menu or not.
So, now if your program to go inside in if then check the customer order is inside your menu or not.
Code:
menu = "Baguette , Crossiant , Coffee , Tea , Cappuccino "
print(menu)
order = input("What Would you like? \n ")
if order in menu:
name = input("What your name? \n ")
amount = input("How many " order " would you like?")
print( name " Your " amount " " order " will be ready soon!\n\n\n")
price = int(4)
#converts number into intenger to do math correctly (int)
total = price * int(amount)
#turns total into string intead of intenger to prevent error in terminal
print("Thank you, your total is: $" str(total))
print("Your " amount " of " order " is ready!")
print("Please enjoy you " order "!")
print("Please come again!")
else:
#If not on menu stops running
print("Sorry Thats not on the menu")
quit()
Note:'tea' will not go inside as tea and Tea not same for machine