Project for Python Create an application containing the following: 2+ user defin
ID: 3573237 • Letter: P
Question
Project for Python Create an application containing the following: 2+ user defined classes data members per class including at least one use of an list including at least one use of a dictionary (dictionary value should be acomplex object, not just a simple value such as number or string) 2+ manipulation methods per class Demonstrate the use of if/if-else statements while loops forloops, including use of range exceptions (try except 1 or more nested loops (whileand/orfor File IO for reading and writing data Import library and use of imported library objects Due at 4:00pm Dec 12, 2016 University of Colorado ll 2016Explanation / Answer
Program for the petstore manager to keep track of animals for adoption.
Animal.py
class Animal:
animal_type = None
name = None
available_for_adoption = None
def __init__(self, animal_type, name, available_for_adoption):
self.animal_type = animal_type
self.name = name
self.available_for_adoption = available_for_adoption
PetStore.py
import Animal
class PetStore:
animals = None
def __init__(self):
self.animals = []
def add_animal(self, animal):
self.animals.append(animal)
def delete_animal(self, name):
for animal in self.animals:
if animal.name == name:
self.animals.remove(animal)
return True
return False
petstoremanager.py
from PetStore import PetStore
from Animal import Animal
petstore = PetStore()
choice = input("Pet Store Options ----------- 1. Add Animal 2. Delete Animal 3. Show Animals 4. Exit What would you like to do? ")
while choice!=4:
if choice == 1:
animal_type = raw_input("What type of animal would you like to create? ")
name = raw_input("What is the animal's name? ")
a = raw_input("Is the animal available for adoption?(y/n) ")
if a=='y':
available_for_adoption = True
else:
available_for_adoption = False
animal = Animal(animal_type, name, available_for_adoption)
petstore.add_animal(animal)
elif choice == 2:
name = raw_input("What is the animal's name you'd like to remove? ")
deleted = petstore.delete_animal(name)
if deleted:
print name+" has been removed."
else:
print name+" could not be found"
elif choice == 3:
print "Animal List ----------- "
for animal in petstore.animals:
if animal.available_for_adoption==True:
avail = "is available"
else:
avail = "is not available"
print animal.name + " is " + animal.animal_type + " and " +avail
choice = input("Pet Store Options ----------- 1. Add Animal 2. Delete Animal 3. Show Animals 4. Exit What would you like to do? ")
print "Thank you for visiting the Pet Store!"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.