Question: Create a method in the Person class which returns how another person's age compares. Given the objects p1, p2 and p3, which will be initialized

Create a method in the Person class which returns how another person's age compares. Given the objects p1, p2 and p3, which will be initialized with the attributes name and age, return a sentence in the following format:

{other_person} is {older than / younger than / the same age as} me.

Examples:

p1 = Person("Samuel", 24)

p2 = Person("Joel", 36)

p3 = Person("Lily", 24)

p1.compare_age(p2) "Joel is older than me."

p2.compare_age(p1) "Samuel is younger than me."

p1.compare_age(p3) "Lily is the same age as me."

using python program

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 Databases Questions!