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.

  1. 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.
  2. What is the type of the instance?
  3. What is the type of the class?
  4. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!