
Patrick B. answered 02/25/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
firstName="Patrick"
lastName="Baldwin"
dob="02/11/1968"
myTeacher = Person(firstName,lastName,dob)
print(myTeacher.getFullname())
print("dob = "+ myTeacher.getDOB())
print(myTeacher.getAge())