Calculate Bill

Steven D'Aprano steve at pearwood.info
Tue Mar 29 20:50:45 EDT 2016


On Wed, 30 Mar 2016 09:33 am, Yum Di wrote:


[...]
> print ("Thank You for ordering at Pizza Shed! ")
> 
> Hey.. this code works. However, i need it to calculate the total cost.
> I dont know how to do that. Can someone help me..
> thanks


Think about how people calculate the bill at a real pizza restaurant.

Every time you order something, they write it down in a list:

seafood
thin and crispy
extra cheese
pineapple
Fizzy Orange


The list goes to the cook, who prepares the order, then when you're ready to
pay, it goes to somebody who works out the prices.

In your case, you don't need to care about the cook. So you can record the
prices of each item in a list:


prices = []  # No items have been ordered.

# Order 3 seafood pizzas:

prices.append(5.60 * 3)

and so on, for all the extra topics, drinks, deserts, anything else they
order.

Then, you calculate the total:

sum(prices)



-- 
Steven




More information about the Python-list mailing list