Menu

[Solved]Python 3 2 Implement Class Person Supports Methods Int Constructor Takes Input Person S Na Q37080725

Python 3+

2. Implement a class Person that supports these methods:

a) __int__(): A constructor that takes as input a person’s name(as a string) and birth year (as an integer)

b) age(): Returns the age of the person.

c) name(): Returns the name of the person

3. Implement following two subclasses of theclass person.

a) The class Instructor supports methods:

i) __int__(): Constructor that takes the person’s degree inaddition to name and birth year

ii) degree(): Returns the degree of the instructor.

iii) __repr__(self): Returns the canonical stringrepresentation      

iv) __str__(self): Returns the pretty print representation

b) The class Student, also a subclass of classPerson, supports:

i) __int__(): Constructor that takes the person’s major inaddition to name and birth year

ii) major(): Returns the major of the student.

iii) __repr__(self): Returns the canonical stringrepresentation      

iv) __str__(self): Returns the pretty print representation

Your implementation of the three classes should behave as shownin the next code:

>>> i1 = Instructor(‘Jones’, 1978, ‘PhD’)

>>> i1.name()

‘Jones’

>>> i1.age()

41

>>> i1.degree()

‘PhD’

>>> i1

Instructor(Name: Jones; Degree: PhD)

>>> print(i1)

I am an Instructor. My name is Jones. I am 41. I have a PhD.

>>> s1 = Student(‘Smith’, 1998, ‘Computer Science’)

>>> s1.age()

21

>>> s1.name()

‘Smith’

>>> s1.major()

‘Computer Science’

>>> s1

Student(Name: Smith; Degree: Computer Science)

>>> print(s1)

I am a Student. My name is Smith. I am 21. My major is ComputerScience.

>>>

Expert Answer


Answer to Python 3+ 2. Implement a class Person that supports these methods: a) __int__(): A constructor that takes as input a per… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *