Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions