-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_fruits_in_basket.py
More file actions
33 lines (24 loc) · 899 Bytes
/
count_fruits_in_basket.py
File metadata and controls
33 lines (24 loc) · 899 Bytes
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
### Example 1
result = 0
basket_items = {'pears': 5, 'grapes': 19, 'kites': 3, 'sandwiches': 8, 'bananas': 4}
fruits = ['apples', 'oranges', 'pears', 'peaches', 'grapes', 'bananas']
### Count fruits in a basket
for each_fruit in fruits:
result += basket_items.get(each_fruit, 0)
print(result)
### Example 2
result = 0
basket_items = {'peaches': 5, 'lettuce': 2, 'kites': 3, 'sandwiches': 8, 'pears': 4}
fruits = ['apples', 'oranges', 'pears', 'peaches', 'grapes', 'bananas']
### Count fruits in a basket
for each_fruit in fruits:
result += basket_items.get(each_fruit, 0)
print(result)
### Example 3
result = 0
basket_items = {'lettuce': 2, 'kites': 3, 'sandwiches': 8, 'pears': 4, 'bears': 10}
fruits = ['apples', 'oranges', 'pears', 'peaches', 'grapes', 'bananas']
### Count fruits in a basket
for each_fruit in fruits:
result += basket_items.get(each_fruit, 0)
print(result)