Question
Exercise #1: (5 points) Here is a Person class definition: import datetime class Person: def __init__(self, name, surname, birthdate, address, telephone, email): self.name = name
Exercise #1:(5 points)
Here is a Person class definition:
import datetime class Person: def __init__(self, name, surname, birthdate, address, telephone, email): self.name = name self.surname = surname self.birthdate = birthdate self.address = address self.telephone = telephone self.email = email def age(self): today = datetime.date.today() age = today.year - self.birthdate.year if today < datetime.date(today.year, self.birthdate.month, self.birthdate.day): age -= 1 return age person = Person( "Jane", "Doe", datetime.date(1992, 3, 12), # year, month, day "No. 12 Short Street, Greenville", "555 456 0987", "..e@example.com" ) print(person.name) print(person.email) print(person.age())
Exercise #4:
Create an instance of thePersonclass from exercise 1. Use thedirfunction on the instance. Then use thedirfunction on the class.
- What happens if you call the __str__ method on the instance? Verify that you get the same result if you callthe str function with the instance as a parameter.
- What is the type of the instance?
- What is the type of the class?
- Write a function which prints out the names and values of all the custom attributes of any object that is passed in as a parameter. (see vars() hint.)
Dir() Hint:
person = Person() print(dir(person))
vars() Hint:
print(vars(person))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started