Coverage for e14_restaurant.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python3
2"""Solution to chapter 4, exercise 14: restaurant"""
5menu = {'sandwich': 10, 'tea': 7, 'salad': 9}
8def restaurant():
9 """Ask the user to enter their dining preferences, one by one, based
10on the global "menu" dict.
12- If the user enters an empty string, stop asking and print the total bill.
13- If the user enters something on the menu (i.e., a key in "menu"), then
14 print the price and the total.
15- If the user enters something not on the menu, then tell them the item isn't
16 available.
17"""
19 total = 0
20 while True:
21 order = input("Order: ").strip()
23 if not order:
24 break
26 elif order in menu:
27 price = menu[order]
28 total += price
29 print(f'{order} costs {price}, total is {total}')
31 else:
32 print(f'We are fresh out of {order} today')
34 print(f'Your total is {total}')