-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicnic.py
More file actions
19 lines (19 loc) · 886 Bytes
/
picnic.py
File metadata and controls
19 lines (19 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#declare dict
allGuests = {'Alice': {'apples': 5, 'pretzels': 12},
'Bob': {'ham sandwiches': 3, 'apples': 2},
'Carol': {'cups': 3, 'apple pies': 1}}
#define lookup function
def totalBrought(guests, item):
numBrought = 0
#loop through dict
for k, v in guests.items():
#increase numBrought by the value of item passed
numBrought = numBrought + v.get(item, 0)
#now that were done looping through dict, return numBrought
return numBrought
print('Number of things being brought:')
print(' - Apples ' + str(totalBrought(allGuests,'apples')))
print(' - Cups ' + str(totalBrought(allGuests,'cups')))
print(' - Cakes ' + str(totalBrought(allGuests,'cakes')))
print(' - Ham Sandwiches ' + str(totalBrought(allGuests,'ham sandwiches')))
print(' - Apple Pies ' + str(totalBrought(allGuests,'apple pies')))