
Jessie M.
asked 02/09/21python help classes and properties
All programming to be done in python (please show input code):
Question Info:
- Create a Person Class which have these properties and methods:
- Properties: fname, lname, DOB
2. Create a child class Student of the Person class. The Student should have:
- Properties: gradeLevel, studentID, courseMarks (dictionary with the course names as keys and course marks as values)
Question To Answer:
Q2.2) getTotal() returns the average for all course marks (use the Python math module)
https://docs.google.com/document/d/13Rkz4-zfbWabKC02JAIzBvWKhORqLu4fCprhCjCGMW0/edit?usp=sharing
1 Expert Answer

Patrick B. answered 02/26/21
Math and computer tutor/teacher
import datetime
class Person:
def __init__ (self,firstname,lastname,dob):
self.fname = firstname
self.lname = lastname
self.dob = dob
def getFullname(self):
return str(self.fname) + " " + str(self.lname)
def getDOB(self):
return str(dob)
def getAge(self):
tokens = self.dob.split("/")
iMonth = tokens[0]
iDay = tokens[1]
iYear = tokens[2]
print("year:month:day=" + str(iYear) + ":" + str(iMonth) + ":" + str(iDay))
today = datetime.date.today()
birthdate = datetime.date(int(iYear),int(iMonth),int(iDay))
years = int(today.year) - int(birthdate.year)
if today.month < birthdate.month or (today.month == birthdate.month and today.day < birthdate.day):
years -= 1
return years
class Student(Person):
def __init__(self,firstname,lastname,dob,studentid,gradelevel):
Person.__init__(self,firstname,lastname,dob)
self.studentID = studentid
self.gradeLevel = gradelevel
self.courseMarks = { "course":"mark" }
def GetStudentID():
return studentID
def GetGradeLevel():
return gradeLevel
def addCourseMarks(self,x,y):
self.courseMarks.update({x:y})
def getTotal(self):
marks = self.courseMarks.values()
#print (marks)
#print(len(marks))
sum=0
for mark in marks:
if mark!="mark":
sum = float(sum) + float(mark)
return sum
def getAverage(self):
return self.getTotal()/(len(self.courseMarks)-1)
#################################################
firstName="Patrick"
lastName="Baldwin"
dob="02/11/1968"
myTeacher = Person(firstName,lastName,dob)
print(myTeacher.getFullname())
print("dob = "+ myTeacher.getDOB())
print(myTeacher.getAge())
firstName="John"
lastName="Smith"
dob="12/01/2006"
gradeLevel="Grade 10"
studentID ="10023"
myStudent=Student(firstName,lastName,dob,studentID,gradeLevel)
print(myStudent.getFullname())
print(myStudent.getAge())
course="Math"
mark=90
myStudent.addCourseMarks(course,mark)
course="Science"
mark=88
myStudent.addCourseMarks(course,mark)
course="Social"
mark=77
myStudent.addCourseMarks(course,mark)
course="LA"
mark=98
myStudent.addCourseMarks(course,mark)
print(myStudent.courseMarks)
print(myStudent.getTotal())
print(myStudent.getAverage())
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
my apologies... Sum and Average methods added02/26/21