CSCI 1523 Program 4
Write a program that creates three pet objects, adds them to a list, and then prints all the objects by iterating through the list. Since Program 2 and 3 were very hard for some, I decided to make Program 4 much easier. If you like to challenge yourself, please do the challenge extra credit partition. __str__ methods in the classes:
? The __str__ method in Pet class returns the pet details: ID, name, symptoms
? The __str__ methods of the subclasses return the pet type plus the pet details.
Sample run: > > > %Run 'CSCI 1523 Program 3. py' Cat: P123, Kitty, symptoms= ['Sleep all day', 'Not eating' ] Dog: P124, Boomer, symptoms= ['Pee every hour' ] Fish: P125, Nemo, symptoms= ['Floating', 'Makes bubbles' ] Classes and their methods: class Pet: def _init_(self, pid, name) def get_pid(self) def get_name (self) def get_symptoms(self) def set_pid(self, pid) def set_name (self, name) def add_symptoms (self, symptom_list) def str_(self) class Cat (Pet) : def _init_(self, pid, name) : def str_(self) : class Fish(Pet) : def _init_(self, pid, name) : def _str_(self) : class Dog (Pet) : def init_(self, pid, name) : def str (self) : Print the pets in the list. This relies on_str_methods to work. for p in pet_list: print (p)Challenge: Extra credit option: Write a Pet data program for an animal hospital >>> %Run 'CSCI 1523 Program 3.py' Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice:4 There are not pets. Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice:1 Enter pet ID :P123 Enter pet name :Kitty Enter pet symptoms (seperate by comma):Not eating, Sleep all day Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice:4 Cat: P123, Kitty, symptoms: ['Not eating', ' Sleep all day'] Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice:2 Enter pet ID :P124 Enter pet name :Boomer Enter pet symptoms (seperate by comma):Pee every hour Pet Emergency Hospital. 1) Add a cat 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice : 3 Enter pet ID : P125 Enter pet name : Nomo Enter pet symptoms (seperate by comma) : Floating, Makes bubbles Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice : 4 Cat: P123, Kitty, symptoms= ['Not eating', ' Sleep all day' ] Dog: P124, Boomer, symptoms= ['Pee every hour' ] Dog: P125, Nomo, symptoms= ['Floating', ' Makes bubbles' ] Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice : 5 Enter PID to look up: P125 Pet found PID = P125 Name = Nomo Symptoms = ['Floating', ' Makes bubbles' ] Pet Emer 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice : 6 > > >