请使用python给我写个宠物管理系统
时间: 2023-08-03 17:02:34 浏览: 49
好的,以下是用Python实现的宠物管理系统代码:
```python
class Pet:
def __init__(self, name, breed, age, color):
self.name = name
self.breed = breed
self.age = age
self.color = color
class PetStore:
def __init__(self):
self.pets = []
def add_pet(self, pet):
self.pets.append(pet)
def remove_pet(self, index):
del self.pets[index]
def print_pets(self):
for pet in self.pets:
print("Name:", pet.name)
print("Breed:", pet.breed)
print("Age:", pet.age)
print("Color:", pet.color)
print()
pet_store = PetStore()
pet1 = Pet("Max", "Dog", 2, "Brown")
pet2 = Pet("Kitty", "Cat", 1, "Black")
pet3 = Pet("Charlie", "Rabbit", 3, "White")
pet_store.add_pet(pet1)
pet_store.add_pet(pet2)
pet_store.add_pet(pet3)
pet_store.print_pets()
pet_store.remove_pet(1)
pet_store.print_pets()
```
这个宠物管理系统同样包含了Pet和PetStore两个类。在这里,我们使用了Python的类和方法来实现宠物的添加、删除和打印。在main函数中,我们创建了一些宠物,并将它们添加到PetStore中,然后打印出宠物列表。然后我们删除了一个宠物,并再次打印宠物列表,以验证删除操作。