Menu

[Solved]Python Pet Class Write Class Named Pet Following Data Attributes Name Name Pet Animaltype Q37037834

Python: Pet Class

Write a class named Pet, which should have the following dataattributes:

  • __name (for the name of a pet)
  • __animal_type (for the type of animal that a pet is. Examplevalues are ‘Dog’, ‘Cat’, and ‘Bird’)
  • __age (for the pet’s age)
  • __gender (for the pet’s gender)
  • __color (for the pet’s color)
  • __size (for the pet’s size)

The pet class should have an __init__ method that creates theseattributes. It should also have the following methods:

  • set_name
    • This method assigns a value to the __name field.

  • set_animal_type
    • This method assigns a value to the __animal_type field.

  • set_age
    • This method assigns a value to the __age field.

  • set_gender
    • This method assigns a value to the __gender field.

  • set_color
    • This method assigns a value to the __color field.

  • set_size
    • This method assigns a value to the __size field.

  • get_name
    • This method assigns a value to the __name field.

  • get_animal_type
    • This method assigns a value to the __animal_type field.

  • get_age
    • This method assigns a value to the __age field.

  • get_gender
    • This method assigns a value to the __gender field.

  • get_color
    • This method assigns a value to the __color field.

  • get_size
    • This method assigns a value to the __size field.

Once you have written the class, write a program that creates anobject of the class and prompts the user to enter the name, type,age, gender, color, and size of his or her pet. This data should bestored as the object’s attributes. Use the object’s accessormethods to retrieve the pet’s name, type, age, gender, color, andsize and display this data on the screen. The program should handlethe data type error lie for age which is supposed to beinteger.

Sample Output(s):

Enter the name of the pet: Pip
Enter the type of animal: Dog
Enter the age of the pet: 4a
Non-numeric error: Age!

Another run…

Enter the name of the pet: Og
Enter the type of animal: Cat
Enter the age of the pet: 9
Enter the gender of the pet: Female
Enter the color of the pet: Black/White
Enter the size of the pet: Small

Here is the data that you entered:
Pet name: Og
Animal type: Cat
Age of pet: 9
Gender of pet:
Female Color of pet: Black/White
Size of pet: Small

Expert Answer


Answer to Python: Pet Class Write a class named Pet, which should have the following data attributes: __name (for the name of a pe… . . .

OR


Leave a Reply

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