Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called Person with the following attributes: name - A string representing the person's name age - An int representing the person's age

Create a class called Person with the following attributes:

  • name - A string representing the person's name
  • age - An int representing the person's age in years

As well as appropriate __init__ and __str__ methods, include the following methods:

  • get_name(self) - returns the name of the person
  • get_age(self) - returns the age of the person
  • set_name(self, new_name) - sets the name for the person
  • set_age(self, new_age) - sets the age for the person
  • is_older_than(self, other) - returns True if this person is older than the one passed as the other parameter, False otherwise

class Person: # TODO: Implement this class properly def __init__(self, name, age): pass

def __str__(self): pass

def get_name(self): pass

def get_age(self): pass

TESTS:

Alice and Bob

Expected Output

Bob is older than Alice

SOMEONE ALREADY GAVE THE ANSWER (BELOW) HOWEVER THE SYSTEM IS NOT ACCEPTING IT AND SAYS: YOU SHOULD CALCULATE THE OUTPUT(PLEASE SEE THE ATTACHMENT)

class person: def __init__(self, name, age): self.name=name self.age=age

def set_name(self, new_name): self.name=new_name

def set_age(self, new_age): self.age=new_age

def __str__(self): return("Name of the person is {} and age is {}".format(self.name,self.age))

def get_name(self): return self.name

def get_age(self): return self.age

def is_older_than(self, other): return(self.get_age()>other.get_age())

p1=person("Bob",30)#creating first object of the class person with name bob and age 30 p2=person("Alice",25)#creating first object of the class person with name alice and age 25 print(p1)#print the values of object p1 print(p2)#print the values of object p2

if(p1.is_older_than(p2)): print("Bob is older than Alice") else: print("Alice is older than Bob")

image text in transcribed

Tests Aice and Bob Run Aun Tests Grade You should caloulate the output Output Name of the person is Bob and age is 30 Name of the person is Alice and age is 25 Bob is older than Alice

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

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

What must a creditor do to become a secured party?

Answered: 1 week ago

Question

Discuss the importance of workforce planning.

Answered: 1 week ago

Question

Differentiate between a mission statement and a vision statement.

Answered: 1 week ago