-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 5.py
More file actions
51 lines (32 loc) · 1.63 KB
/
Copy pathProblem 5.py
File metadata and controls
51 lines (32 loc) · 1.63 KB
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
""" Problem 5: You have been given a list of N integers which represents the number of mangoes in a bag. Each
has variable number of mangoes. There are M students in a guvi class, your task is to distribute
the mangoes in such a way that each students gets one bag. The difference between the number of
mangoes in a bag with maximum mangoes and a bag with minimum mangoes given to student is minimum?"""
# List of number of mangoes (N) in the number of bags
N = [5,3,2,4,7]
N.sort() # sort the list
min_mango = min(N) # Variable to store the bag with minimum mangoes
# Number of bags
no_of_bags = len(N)
# Number of Students(M)
M = int(input("Enter the number of students:"))
given_bags = [] # an empty list to store the distributed bags to the students
# To check the students in the Guvi class is more than the number of bags
if M>no_of_bags:
print("Students in the Guvi class are more than the no. of bags")
else:
for i in N: # iterates through the list of mangoes
if len(given_bags)<M: # checks the number of students to distribute
given_bags.append(i) # append the distributed bags in the given_bags
print(given_bags)
# Variables to store the bags with maximum and minimum mangoes
min = given_bags[0]
max = given_bags[-1]
# Difference of the bags with maximum and minimum mangoes
diff = max-min
print(diff)
# To find the difference b/w max and min bag distributed is minimum
if diff <= min_mango:
print("Minimum")
else:
print("Not minimum")