-
Notifications
You must be signed in to change notification settings - Fork 10
/
sandwichMaker.py
78 lines (63 loc) · 2.5 KB
/
sandwichMaker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'''
Chapter 8 Input Validation
Sandwich Maker
Write a program that asks users for their sandwich preferences. The program
should use PyInputPlus to ensure that they enter valid input, such as:
• Using inputMenu() for a bread type: wheat, white, or sourdough.
• Using inputMenu() for a protein type: chicken, turkey, ham, or tofu.
• Using inputYesNo() to ask if they want cheese.
• If so, using inputMenu() to ask for a cheese type: cheddar, Swiss,
or mozzarella.
• Using inputYesNo() to ask if they want mayo, mustard, lettuce, or tomato.
• Using inputInt() to ask how many sandwiches they want. Make sure this
number is 1 or more.
Come up with prices for each of these options, and have your program
display a total cost after the user enters their selection
'''
import pyinputplus as pyip
prices = {
'breads': {
'wheat': 1.00,
'white': 1.25,
'sourdough': 2.00,
},
'proteins': {
'chicken': 1.50,
'turkey': 1.25,
'ham': 1.75,
'tofu': 2.00,
},
'cheeses': {
'cheddar': 0.75,
'Swiss': 1.25,
'mozzarella': 1.25,
},
'mayo': 0.5,
'mustard': 0.25,
'lettuce': 0.50,
'tomato': 0.50,
}
totalSandwich = 0
breadChoice = pyip.inputMenu(prices['breads'].keys(), prompt='What type of bread do you want? ')
totalSandwich += prices['breads'][breadChoice]
proteinChoice = pyip.inputMenu(prices['proteins'].keys(), prompt='What type of protein do you want? ')
totalSandwich += prices['proteins'][proteinChoice]
cheeseYesNo = pyip.inputYesNo(prompt='Do you want cheese on your sandwich? ')
if cheeseYesNo == 'yes':
cheeseChoice = pyip.inputMenu(prices['cheeses'].keys(), prompt='What kind of cheese do you want? ')
totalSandwich += prices['cheeses'][cheeseChoice]
mayoYesNo = pyip.inputYesNo(prompt='Do you want mayo on your sandwich? ')
if mayoYesNo == 'Yes':
totalSandwich += prices['mayo']
mustardYesNo = pyip.inputYesNo(prompt='Do you want mustard on your sandwich? ')
if mustardYesNo == 'Yes':
totalSandwich += prices['mustard']
lettuceYesNo = pyip.inputYesNo(prompt='Do you want lettuce on your sandwich? ')
if lettuceYesNo == 'Yes':
totalSandwich += prices['lettuce']
tomatoYesNo = pyip.inputYesNo(prompt='Do you want tomato on your sandwich? ')
if tomatoYesNo == 'Yes':
totalSandwich += prices['tomato']
sandwichQuantity = pyip.inputInt(prompt='How many sandwiches do you want? ', min=1)
totalSandwich *= sandwichQuantity
print('Total cost: ${:.2f}'.format(totalSandwich))