Write a class named Pet, which should have the following attributes: 1) name (for the name of a pet); 2) animal_type (fo

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Write a class named Pet, which should have the following attributes: 1) name (for the name of a pet); 2) animal_type (fo

Post by answerhappygod »

Write a class named Pet, which should have the following
attributes: 1) name (for
the name of a pet); 2) animal_type (for the type of animal that a
pet is. Example
values are ‘Dog’, ‘Cat’, and ‘Bird’); 3) age (for the pet’s
age).
The Pet class should have an __init__ method that creates these
attributes. It should
also have the following methods:
• change_name: this method assigns a new value to the name
field
• change_age: this method assigns a new value to the age
field
• get_name: this method returns the value of the name field
• get_animal_type: this method returns the value of the animal_type
field
• get_age: this method returns the value of the age field.
Once you have written the class, write a program that prompts the
user to enter the
name, type, and age of his or her pet; create an object of the Pet
class using the
input data. This data should be stored as the object’s attributes.
Use the object’s
accessor methods to retrieve the pet’s name, type, and age and
display this data on
the screen.
In Python code please
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply