OPA May15 Python

sample input:

4

1
Shivakumar
3
Maths
10
Physics
10
Chemistry
10
2
Rajesh
4
MATHS
5
PHYSICS
5
CHEMISTRY
5
COMPUTERS
5
3
Vasudev
2
MATHS
4
PHYSICS
4
4
Srinivas
3
Maths
8
Physics
8
Chemistry
8
3
maths

 

Output:

 

8

1 Shivakumar {'MATHS': 10, 'PHYSICS': 10, 'CHEMISTRY': 10}

Solutions:

class Professor():
    def __init__(self,profId, profName, subjectsDict):
        self.profId = profId
        self.profName = profName
        self.subjectsDict = subjectsDict
class University():
    def __init__(self, test):
        self.test = "tesint"
    def getTotalExperience(self,profList, profId):
        result = 0
        for item in profList:
            proFId=int(profId)
            if item.profId == proFId:
                for exp in item.subjectsDict.values():
                    result+=exp
        return result
    def selectSeniorProfessorBySubject(self,profList, subjectName):
        result= -9
        found = False
        obj=None
        for item in profList:
            if item.subjectsDict[subjectName.upper()]>= result:
                result = item.subjectsDict[subjectName.upper()]
                found = True
                obj = item
        if found == False:
            return 'None'
        else:
            return str(obj.profId)+" "+ obj.profName+" "+str(obj.subjectsDict)
if __name__ == "__main__":


    T = int(input().strip())
    
    profObjects=[]
    while T>0:
        profId = int(input())
        profName = input().strip()
        numSubjects = int(input().strip())
        subjectDict={}
        while numSubjects>0:
            subjectName = input().strip()
            exp = int(input().strip())
            subjectDict[subjectName.upper()] = exp
            numSubjects-=1
        obj = Professor(profId,profName,subjectDict)
        profObjects.append(obj)
        T-=1
    profSearch = input().strip()
    subjectSearch = input().strip()
    obj = University("tset")
    print(obj.getTotalExperience(profObjects,profSearch))
    print(obj.selectSeniorProfessorBySubject(profObjects, subjectSearch))

.

 

©2018 by The real one. Proudly created with Wix.com