Weekly Project: Pet Shop Simulator
Let's put everything we've learned about objects and classes into practice by creating a simple pet shop simulator.
Your task is to create a program that:
- Defines a base
Animal class with common attributes and methods
- Creates derived classes for different types of pets (e.g., Dog, Cat, Fish)
- Implements a
PetShop class that can add pets, remove pets, and list all pets
- Allows users to interact with the pet shop (add pets, list pets, etc.)
Here's a starting template:
class Animal:
def __init__(self, name, species):
self.name = name
self.species = species
def make_sound(self):
pass
class Dog(Animal):
def make_sound(self):
return f"{self.name} barks!"
class Cat(Animal):
def make_sound(self):
return f"{self.name} meows!"
class PetShop:
def __init__(self):
self.pets = []
def add_pet(self, pet):
self.pets.append(pet)
print(f"{pet.name} has been added to the pet shop.")
def list_pets(self):
if not self.pets:
print("The pet shop is empty.")
else:
for pet in self.pets:
print(f"{pet.name} - {pet.species}")
# Test your Pet Shop Simulator
shop = PetShop()
dog = Dog("Buddy", "Dog")
cat = Cat("Whiskers", "Cat")
shop.add_pet(dog)
shop.add_pet(cat)
shop.list_pets()
print(dog.make_sound())
print(cat.make_sound())
Enhance the Pet Shop Simulator by adding the following features:
- Add a
Fish class that inherits from Animal
- Implement a method to remove pets from the shop
- Add a method to feed all the pets in the shop
- Create a simple menu system for users to interact with the pet shop
- Add error handling for invalid inputs or actions
This project will give you hands-on experience with classes, objects, inheritance, and basic user interaction. Have fun creating your Pet Shop Simulator!