hw03: Ordering at a restaurant
- Due before the beginning of class on Wednesday, January 14
The task
You need to write software to keep track of how much food people order at a restaurant.
To do this, you should define a class in Python called
Table, with the following methods:
__init__: Set the current order total to zeroorder: Takes in the name and price of one item of food, prints out a string indicating that you are ordering this, and adds the cost to the running totalpay: Takes in a tip amount (percentage), and returns the total cost of the food plus tip
Using your Table class, the following code should work to read in
orders and then print out the total:
t1 = Table()
while True:
line = input("Enter item and price (or 'done'): ")
if line.strip() == 'done':
break
item, price = line.split()
price = float(price)
t1.order(item, price)
cheap = t1.pay(10)
nice = t1.pay(25)
print(f"Total with 10% tip would be {round(cheap,2)}, or with 25% would be {round(nice,2)}")
Your code
Run git pull in your sd212 directory and you should see a new folder
for this hw with a file table.py for you to fill in. This will already
have the code above to read in orders and you must not change that
part. You just need to fill in the definition of the Table
class at the top.
Example
For example, running your code should look like this (where green is what the user types in at the terminal):
Enter item and price (or 'done'):coke 5.50Ordering cokeEnter item and price (or 'done'):steak 22Ordering steakEnter item and price (or 'done'):broccoli 9Ordering broccoliEnter item and price (or 'done'):doneTotal with 10% tip would be 40.15, or with 25% would be 45.62
Submit command
To submit files for this homework, run one of these commands:
submit -c=sd212 -p=hw03 table.py
club -csd212 -phw03 table.py