Skip to content

Commit 5ba544f

Browse files
Day 12: Inheritance
1 parent 0fe862a commit 5ba544f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Day 12: Inheritance.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class Person:
2+
def __init__(self, firstName, lastName, idNumber):
3+
self.firstName = firstName
4+
self.lastName = lastName
5+
self.idNumber = idNumber
6+
def printPerson(self):
7+
print("Name:", self.lastName + ",", self.firstName)
8+
print("ID:", self.idNumber)
9+
10+
class Student(Person):
11+
# Class Constructor
12+
#
13+
# Parameters:
14+
# firstName - A string denoting the Person's first name.
15+
# lastName - A string denoting the Person's last name.
16+
# id - An integer denoting the Person's ID number.
17+
# scores - An array of integers denoting the Person's test scores.
18+
#
19+
# Write your constructor here
20+
def __init__(self, firstName, lastName, idNumber,scores):
21+
super().__init__(firstName, lastName, idNumber)
22+
23+
# Function Name: calculate
24+
# Return: A character denoting the grade.
25+
#
26+
# Write your function here
27+
def calculate(self):
28+
a = sum(scores)/len(scores)
29+
if a>=90:
30+
return "O"
31+
elif a>=80:
32+
return "E"
33+
elif a>=70:
34+
return "A"
35+
elif a>=55:
36+
return "P"
37+
elif a>=40:
38+
return "D"
39+
else:
40+
return "T"
41+
42+
line = input().split()
43+
firstName = line[0]
44+
lastName = line[1]
45+
idNum = line[2]
46+
numScores = int(input()) # not needed for Python
47+
scores = list( map(int, input().split()) )
48+
s = Student(firstName, lastName, idNum, scores)
49+
s.printPerson()
50+
print("Grade:", s.calculate())

0 commit comments

Comments
 (0)