# HackerRank Day 12 Solution in Python: Inheritance

Today we will see the HackerRank Day 12 Solution in Python. The problem is named Inheritance which is part of 30 Days of code on HackerRank. Let’s get started!

## Day 12: Inheritance Problem statement

We are given two classes, Person and Student, where Person is the base class and Student is the derived class. The code for Person and a declaration for Student are already provided for us. Our task is to create a constructor for the Student class which inherits all the properties of the Person class. Also, have to complete the calculate() method that calculates a Student object’s average and returns the graded character corresponding to their calculated average.

Sample Input
Heraldo Memelli 8135627
2
100 80

Sample Output
Name: Memelli, Heraldo
ID: 8135627

Explanation: This student had 2 scores to average: 100 and 80. The student’s average grade is 90 which corresponds to the letter grade O, as given in the problem statement.

You can solve the problem here.

## HackerRank Day 12 Solution in Python

```class Person:
def __init__(self, firstName, lastName, idNumber):
self.firstName = firstName
self.lastName = lastName
self.idNumber = idNumber

def printPerson(self):
print("Name:", self.lastName + ",", self.firstName)
print("ID:", self.idNumber)

class Student(Person):
#Constructor for Student class
def __init__(self, firstName, lastName, idNumber, scores):
super().__init__(firstName, lastName, idNumber)
self.scores = scores

# Calculate Student object's average and return corresponding grade
def calculate(self):
avg = sum(self.scores) / len(self.scores)
if avg>=90 and avg<=100:
elif avg>=80:
elif avg>=70:
elif avg>=55:
elif avg>=40:
else:

line = input().split()
firstName = line
lastName = line
idNum = line
numScores = int(input())
scores = list( map(int, input().split()) )
s = Student(firstName, lastName, idNum, scores)
s.printPerson()

Most of the code is already present there, you need to copy and paste this code only:

``````class Student(Person):
#Constructor for Student class
def __init__(self, firstName, lastName, idNumber, scores):
super().__init__(firstName, lastName, idNumber)
self.scores = scores

# Calculate Student object's average and return corresponding grade
def calculate(self):
avg = sum(self.scores) / len(self.scores)
if avg>=90 and avg<=100:
elif avg>=80:
elif avg>=70:
elif avg>=55:
elif avg>=40:
else: 