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.
Question shou say what to do if the avarage results in a float not an integer. (round up, down or just dismiss the floating part).
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):def__init__(self,firstName,lastName,idNumber,scores):self.firstName=firstNameself.lastName=lastNameself.idNumber=idNumberself.scores=scoresdefcalculate(self):relation={"T":[iforiinrange(0,40)],"D":[iforiinrange(40,55)],"P":[iforiinrange(55,70)],"A":[iforiinrange(70,80)],"E":[iforiinrange(80,90)],"O":[iforiinrange(90,101)],}avg=sum(self.scores)/len(self.scores)forkey,valueinrelation.items():ifint(avg)invalue:returnkey# 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 here# Function Name: calculate# Return: A character denoting the grade.## Write your function hereline=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 →
Question shou say what to do if the avarage results in a float not an integer. (round up, down or just dismiss the floating part).