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

I would like to make my program display the order total/invoice

Here is what ive done:

food =["cheeseburger", "smallchips", "drink"]
prices =[2.50, 1.50, 1]
x=0

myorderfood=[]
myordercost=[]

print("Burgers\n")

print("Menu:")
print("Cheeseburger. Cost - $2.50 each")
print("Small chips. Cost - $1.50 each")
print("Drink - Cola only. Cost - $1.00 each\n")

I want to display an invoice at the end once the user has completed there order showing there total price.

This is some of my code for just the drinks, same type of code used for cheeseburger etc. :

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

while True:
    try:
        drinkselect = input("Please select which drink:\n")
        if  drinkselect == "cola":
            quantitydrink = int(input("How many would you like?\n"))

    except ValueError:
            print("Not valid")
            continue

    if drinkselect != "cola":
        print("Not on our menu!\n")
    else:
         print("good choice\n")
         break

>Solution :

You can use something like this:

from statistics import quantiles
from xml.etree.ElementPath import prepare_predicate


food =["cheeseburger", "smallchips", "drink"]
prices =[2.50, 1.50, 1]
x=0
price = 5
quantitydrink = 0
myorderfood=[]
myordercost=[]

print("Burgers\n")

print("Menu:")
print("Cheeseburger. Cost - $2.50 each")
print("Small chips. Cost - $1.50 each")
print("Drink - Cola only. Cost - $1.00 each\n")
print("10% GST applies to total amount (including both food and delivery)")
print("Delivery is free for food orders that are $30 or more")
print("Delivery cost is an additional $5 for food orders below $30\n")
while True:
    try:
        drinkselect = input("Please select which drink:\n")
        if  drinkselect == "cola":
            quantitydrink += int(input("How many would you like?\n"))

    except ValueError:
            print("Not valid")
            continue

    if drinkselect != "cola":
        print("Not on our menu!\n")
    else:
        print("good choice\n")
        price += 1 * quantitydrink
        print(f"Your total cost is {price}!")
        break

So the base price is 5 for the delivery and if you pick cola it adds the price of the cola multiplied by the amount you purchase to the price variable.

The += operator is best for this.

Changes:

price = 5 #added this on line 8 because the delivery cost is 5 so that is the base price
quantitydrink = 0 #added this on line 9 so you can add the amount to it later in the code
quantitydrink += int(input("How many would you like?\n")) # changed this in line 26 to add the amount you are ordering to the initial value.
price += 1 * quantitydrink # added this in line 36 to calculate the price based on how many colas you are ordering and the base price
print(f"Your total cost is {price}!") #added this at line 37 to print the final price of the order

hope this helps!

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