0 like 0 dislike
8,889 views
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:
                blood.unitinHand-=units
                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:
                minBloodList.append(blood.bloodGroup)
        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: "))
        bloodList.append(Blood(blood_grp,units))
    
    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):
        self.bloodGroup=bg.upper()
        self.unitInHand=units
        
class BloodBank:
    def __init__(self,bl):
        self.bloodList=bl

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

if __name__=='__main__':                
        
    bl=[]
    n=int(input())
    for i in range(n):
        bg=input()
        units=int(input())
        bl.append(Blood(bg,units))
    
    o=BloodBank(bl)
    b=input()
    u=int(input())
    ba=o.isBloodAvailable(b,u)
    if ba==True:
        print("Blood Available")
    else:
        print("Blood not Available")
    print(o.findMinBloodStock())

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 .