-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfruit.py
More file actions
29 lines (24 loc) · 1014 Bytes
/
fruit.py
File metadata and controls
29 lines (24 loc) · 1014 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
def nfruits(dict, fruits_eaten):
'''
a function "nfruits" that takes two arguments:
* A non-empty dictionary containing type of fruit and its quantity initially with Python when he leaves home (length < 10)
* A string pattern of the fruits eaten by Python on his journey as observed by Cobra.
This function should return the maximum quantity out of the different types of fruits that is available with Python when he has reached the campus.
'''
for item in fruits_eaten[:-1]:
for fruit in dict:
if fruit==item:
dict[fruit] -= 1
else:
dict[fruit] += 1
#deal with the last eaten fruit
item = fruits_eaten[-1]
for fruit in dict:
if fruit==item:
dict[fruit] -= 1
#find the maximum of quantity of the fruits left
max_fruit = 0
for fruit in dict:
if dict[fruit] > max_fruit:
max_fruit = dict[fruit]
return max_fruit