I'm trying to make a virtual coffee shop, in which the amount of an item a customer asks for would adjust the total for payment. However, when I run my code, and I enter more than 1 of an item, it simply skips the step that would inform the user of their total.
Code:
import time
print("Hello! Welcome to George's Coffee.")
name = input("What is your name for the order?\n")
print("\nHello " name "! Thank you for coming to George's Coffee!\n")
print("On todays menu, we have the following:\n" "Lattee\n" "Hot Chocolate\n" "Mocha\n" "Celcius\n" "Cappuchino\n" "Black Coffee\n" "All items are $8 because we need money to fund the hacking of the government.")
price = 8
order = input("\nWhat would you like to order today?\n")
quantity = input("How many " order "s would you like?\n")
#singular (=1)
if quantity == "1":
if order == "Lattee":
latte_total = float(2.95) * int(quantity)
print("Amazing choice! That will be $" str(latte_total) ". Please enter your credit card.")
elif order == "Hot Chocolate":
hot_chocolate_total = 2 * int(quantity)
print("Amazing choice! That will be $" str(hot_chocolate_total) ". Please enter your credit card.")
elif order == "Mocha":
mocha_total = 5 * int(quantity)
print("Amazing choice! That will be $" str(mocha_total) ". Please enter your credit card.")
elif order == "Celcius":
cel_total = 2 * int(quantity)
print("Amazing choice! That will be $" str(cel_total) ". Please enter your credit card.")
elif order == "Cappuchino":
capp_total = 6 * int(quantity)
print("Amazing choice! That will be $" str(capp_total) ". Please enter your credit card.")
elif order == "Black Coffee":
coffee_total = 3 * int(quantity)
print("Amazing choice! That will be $" str(coffee_total) ". Please enter your credit card.")
else:
total = price * int(quantity)
print("Amazing choice! That will be $" str(total) ". Please enter your credit card.")
time.sleep(3)
print("\nYour " quantity " " order " will be ready soon! Please have a seat, and we will call your name when it's ready.\n")
time.sleep(10)
print(name "! Your " order " is ready! Please come collect it.\n")
time.sleep(2)
print("Enjoy your beverage, " name ("!"))
Output: terminal output This is my first time posting, so it made it a link
Output when I only do 1: terminal output with only 1
Let me know how I can solve this. Thanks for your help in advance.
CodePudding user response:
In your code you are using
if quantity == "1":
do all the price calculations
That's why it is only working when you get just 1 item, quantity is equal to "1". When you use another quantity the if statement just ignores the rest of the code.
To solve this issue you can delete that line.
import time
print("Hello! Welcome to George's Coffee.")
name = input("What is your name for the order?\n")
print("\nHello " name "! Thank you for coming to George's Coffee!\n")
print("On todays menu, we have the following:\n" "Lattee\n" "Hot Chocolate\n" "Mocha\n" "Celcius\n" "Cappuchino\n" "Black Coffee\n" "All items are $8 because we need money to fund the hacking of the government.")
price = 8
order = input("\nWhat would you like to order today?\n")
quantity = input("How many " order "s would you like?\n")
#singular (=1)
if order == "Lattee":
latte_total = float(2.95) * int(quantity)
print("Amazing choice! That will be $" str(latte_total) ". Please enter your credit card.")
elif order == "Hot Chocolate":
hot_chocolate_total = 2 * int(quantity)
print("Amazing choice! That will be $" str(hot_chocolate_total) ". Please enter your credit card.")
elif order == "Mocha":
mocha_total = 5 * int(quantity)
print("Amazing choice! That will be $" str(mocha_total) ". Please enter your credit card.")
elif order == "Celcius":
cel_total = 2 * int(quantity)
print("Amazing choice! That will be $" str(cel_total) ". Please enter your credit card.")
elif order == "Cappuchino":
capp_total = 6 * int(quantity)
print("Amazing choice! That will be $" str(capp_total) ". Please enter your credit card.")
elif order == "Black Coffee":
coffee_total = 3 * int(quantity)
print("Amazing choice! That will be $" str(coffee_total) ". Please enter your credit card.")
else:
total = price * int(quantity)
print("Amazing choice! That will be $" str(total) ". Please enter your credit card.")
time.sleep(3)
print("\nYour " quantity " " order " will be ready soon! Please have a seat, and we will call your name when it's ready.\n")
time.sleep(10)
print(name "! Your " order " is ready! Please come collect it.\n")
time.sleep(2)
print("Enjoy your beverage, " name ("!"))