python code of 10 july



# Enter your code here. Read input from STDIN. Print output to STDOUT
class Student:
    def init(self,name,sub1,sub2,sub3):
        self.name=name
        self.sub1=sub1
        self.sub2=sub2
        self.sub3=sub3

    def calculateResult(self):
        average=0
        if(self.sub1>=40 and self.sub2>=40 and self.sub3>=40):
            average=(self.sub1+self.sub2+self.sub3)/3
        return average

class School:
    def init(self,name,studentDict):
        self.name=name
        self.studentDict=studentDict

    def getStudentResult(self):
        for i in self.studentDict.keys():
            avg=i.calculateResult()
            if(avg>60):
                self.studentDict[i]="pass"
        return self.studentDict

    def findStudentWithHighestMarks(self,lis):
        if len(lis)==0:
            return None
        else:
            dic2={}
            avg=0
            for i in lis:
                avg=i.calculateResult()
                dic2[i]=avg
            maximum=max(dic2,key=dic2.get)
            return maximum

if(name=="main"):
    n=int(input())
    dic={}
    lis1=[]
    for i in range(n):
        name=input()
        sub1=float(input())
        sub2=float(input())
        sub3=float(input())
        st=Student(name,sub1,sub2,sub3)
        dic[st]="fail"
    school_name=input()
    sc=School(school_name,dic)
    dic=sc.getStudentResult()
    for j in dic:
        if(dic[j]=="pass"):
            lis1.append(j)
    obj=sc.findStudentWithHighestMarks(lis1)
    for k in lis1:
        print (k.name)
    if(obj==None):
        print("No Student Passed")
    else:
        print(obj.name)

No comments:

Post a Comment