0 like 0 dislike
in Service-based-companies by Expert (17,730 points) | 8,889 views

2 Answers

1 like 0 dislike
Best answer
class Blood:
    def __init__(self, bloodGroup, unitinHand):
        self.bloodGroup = bloodGroup
        self.unitinHand = unitinHand

class BloodBank:
    def __init__(self,bloodList):
        self.bloodList = bloodList

    def isBloodAvailable(self, blood_grp, units):
        for blood in self.bloodList:
            if blood.bloodGroup==blood_grp and units<=blood.unitinHand:
                return True
        return False

    def findMinBloodStock(self):
        minBloodCounts = self.bloodList[0].unitinHand
        minBlood = self.bloodList[0].bloodGroup
        for i in range(1,len(self.bloodList)):
            if(self.bloodList[i].unitinHand < minBloodCounts):
                minBlood = self.bloodList[i].bloodGroup
                minBloodCounts = self.bloodList[i].unitinHand
        minBloodList = []
        for blood in self.bloodList:
            if blood.unitinHand == minBloodCounts:
        return minBloodList

if __name__ == '__main__':
    bloodList = []
    for _ in range(int(input())):
        blood_grp = input("Enter the blood group: ").upper()
        units = int(input("Units present in the blood bank: "))
    blood_req = input("Enter required blood group: ").upper()
    units = int(input("Enter units of blood required: "))
    print("Blood is available" if BloodBank(bloodList).isBloodAvailable(blood_req,units) else "Blood is not available")
    print(*BloodBank(bloodList).findMinBloodStock(), sep = ",")
by Expert (610 points)
selected by
0 like 0 dislike

Python Problem : 

Solution :




by Expert (17,730 points)
1 0
My solution:>>>

class Blood:
    def __init__(self,bg,units):
class BloodBank:
    def __init__(self,bl):

    def isBloodAvailable(self,b,u):
        y = False
        for i in self.bloodList:
            if i.bloodGroup==b:
                if i.unitInHand>=u:
                    y = True
        return y            
    def findMinBloodStock(self):
        for i in self.bloodList:
            if i.unitInHand<minn:
        for i in self.bloodList:
            if i.unitInHand==minn:
        return ''

if __name__=='__main__':                
    for i in range(n):
    if ba==True:
        print("Blood Available")
        print("Blood not Available")

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .