Question

please use python answering the question thanks Person Implement the Person class. Each person P has...

please use python answering the question thanks

Person

Implement the Person class.

Each person P has attributes name, age and job.

The constructor accepts arguments for the attributes above, in the order above.

Each person P has a celebrate_birthday() method, which:

increments P's age;

sets P's job to "Retired" if their age is now 65 or greater;

returns "Happy birthday <name>!", where <name> is P's name.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class Person:
    def __init__(self, name, age, job):
        self.name = name
        self.age = age
        self.job = job

    def celebrate_birthday(self):
        self.age += 1
        if self.age >= 65:
            self.job = "Retired"
        return "Happy birthday " + self.name + "!"


p = Person("ronaldo", 63, "footballer")
print("Name:", p.name, "Age:", p.age, "Job:", p.job)
print(p.celebrate_birthday())
print("After 1 birthday")
print("Name:", p.name, "Age:", p.age, "Job:", p.job)
print(p.celebrate_birthday())
print("After another birthday")
print("Name:", p.name, "Age:", p.age, "Job:", p.job)

Name: ronaldo Age Happy birthday ronaldo! After 1 birthday Name: ronaldo Age Happy birthday ronaldo! After another birthday Name: ronaldo Age: 65 Job: Retired

Add a comment
Know the answer?
Add Answer to:
please use python answering the question thanks Person Implement the Person class. Each person P has...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

  • SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The...

    SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable of type double named radius to represent the radius. Set to 1. Constructor Methods: Python : An overloaded constructor method to create a default circle. C# & Java: Default Constructor with no arguments. C# & Java: Constructor method that creates a circle with user-specified radius. Method getRadius() that returns the radius. Method setRadius()...

  • PLEASE YOU PYTHON 3 TO SOLVE! THANKS! PLEASE YOU PYTHON 3 TO SOLVE! THANKS! Example 1...

    PLEASE YOU PYTHON 3 TO SOLVE! THANKS! PLEASE YOU PYTHON 3 TO SOLVE! THANKS! Example 1 Design a class named Information that holds the following personal data: .name, age, address (this attribute has a default value of “unknown"), and phone number. . All the attributes are defined as private. • Write appropriate accessor and mutator methods. • Complete the definition of the str_ method, such that it displays each Information object's data in the following format: name: "Sarah Jones” –...

  • PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to...

    PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Python...

  • Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains...

    Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains instance data that represents the dog's name and dog's age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in "person years" (seven times age of dog. Include a toString method that returns a one-time description of the dog (example below)....

  • Write a Python class, Circle, constructed by a radius and two methods which will compute the...

    Write a Python class, Circle, constructed by a radius and two methods which will compute the area and the perimeter of a circle. Include the constructor and other required methods to set and get class attributes. Create instances of Circle and test all the associated methods. Write a Python class, Rectangle, constructed by length and width and a method which will compute the area of a rectangle. Include the constructor and other required methods to set and get class attributes....

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and...

    Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and will add various functionality. We will store the following private variables specific to Warehouse: . a std::vector of float values which indicate the monetary values of each sale made by this salesman . a std::string which stores that salesman's position title . a float which stores their commission percentage, i.e., the percentage of sales they receive as a paycheck . a float which stores...

  • PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...

    PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a method that adds all persons Validate all input, not left empty for First Name, Last Name, Gender and numeric for age and throw an exception if it does not validate within the class. Create a Student Class that: Inherits the Person Class Accepts GPA Validate GPA (>= 0 and <= 4.0) and throw exception if it does not validate within the class. Has methods...

  • using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...

    using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT