-
Notifications
You must be signed in to change notification settings - Fork 0
/
blood.py
40 lines (33 loc) · 1.15 KB
/
blood.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
class Blood:
def __init__(self,bloodgroup,unitInHand):
self.bloodgroup = bloodgroup
self.unitInHand = unitInHand
class BloodBank:
def __init__(self,bloods):
self.bloods = bloods
def isBloodAvailable(self,bloodgroup,unitreq):
for blood in self.bloods:
if blood.bloodgroup.lower() == bloodgroup.lower() and blood.unitInHand >= unitreq:
return True
return False
def findMinBloodStock(self):
runningshort = []
mini = min(self.bloods,key = lambda blood:blood.unitInHand)
for blood in self.bloods:
if mini.unitInHand == blood.unitInHand:
runningshort.append(blood)
return runningshort
if __name__ == "__main__":
n = int(input())
bloods = []
for _ in range(n):
bloods.append(Blood(input(),int(input())))
bloodbank = BloodBank(bloods)
bloodgroup = input()
low = int(input())
if bloodbank.isBloodAvailable(bloodgroup,low):
print("Blood Available")
else:
print("Blood not Available")
for bg in bloodbank.findMinBloodStock():
print(bg.bloodgroup)