We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
classPerson:def__init__(self,firstName,lastName,idNumber):self.firstName=firstNameself.lastName=lastNameself.idNumber=idNumberdefprintPerson(self):print("Name:",self.lastName+",",self.firstName)print("ID:",self.idNumber)classStudent(Person):# Class Constructor# # Parameters:# firstName - A string denoting the Person's first name.# lastName - A string denoting the Person's last name.# id - An integer denoting the Person's ID number.# scores - An array of integers denoting the Person's test scores.## Write your constructor heredef__init__(self,firstName,lastName,idNumber,scores):Person.__init__(self,firstName,lastName,idNumber)self.scores=scores# Function Name: calculate# Return: A character denoting the grade.## Write your function heredefcalculate(self):average=sum(self.scores)/len(self.scores)letter=''"ifaverage<40:letter='T'elif40<=average<55:letter='D'elif55<=average<70:letter='P'elif70<=average<80:letter='A'elif80<=average<90:letter='E'elif90<=average<=100:letter='O'return(letter)line=input().split()firstName=line[0]lastName=line[1]idNum=line[2]numScores=int(input())#notneededforPythonscores=list(map(int,input().split()))s=Student(firstName,lastName,idNum,scores)s.printPerson()print("Grade:",s.calculate())
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 12: Inheritance
You are viewing a single comment's thread. Return to all comments →
Python Code: This is my solution: