106 lines
3.2 KiB
Python
106 lines
3.2 KiB
Python
class Plant:
|
|
def __init__(self, name, height, color, bloom, Prize):
|
|
self.name = name
|
|
self.height = height
|
|
self.color = color
|
|
self.bloom = bloom
|
|
self.Prize = Prize
|
|
|
|
def grow(self, heigt: int = 1) -> None:
|
|
self.height += heigt
|
|
print(f"{self.name} grew {heigt}cm")
|
|
|
|
|
|
class Garden:
|
|
def __init__(self, owner: str):
|
|
self.owner = owner
|
|
self._plants: list[Plant] = []
|
|
self.score = 0
|
|
|
|
def add_plant(self, plant: Plant) -> None:
|
|
self._plants.append(plant)
|
|
print(f"Added {plant.name} to {self.owner}'s garden")
|
|
|
|
def help_all_plants_grow(self) -> int:
|
|
print(f"\n{self.owner} is helping all plants grow...")
|
|
count = 0
|
|
for plant in self._plants:
|
|
plant.grow(1)
|
|
count += 1
|
|
return (count)
|
|
|
|
def list_plants(self) -> None:
|
|
print(f"\n=== {self.owner}'s Garden Report ===")
|
|
print("Plants in garden:")
|
|
for plant in self._plants:
|
|
display = f"- {plant.name}: {plant.height}cm"
|
|
if (plant.color != ""):
|
|
display += f", {plant.color} flowers"
|
|
if (plant.bloom == 1):
|
|
display += " (blooming)"
|
|
if (plant.Prize > 0):
|
|
display += f", Prize point: {plant.Prize}"
|
|
print(display)
|
|
|
|
def list_update(self, height) -> None:
|
|
regular = 0
|
|
flowering = 0
|
|
prize = 0
|
|
print(f"\nPlants added: {len(self._plants)}, Total growth: {height}cm")
|
|
for plant in self._plants:
|
|
if plant.bloom == 1:
|
|
flowering += 1
|
|
if plant.Prize > 0:
|
|
prize += 1
|
|
if (plant.Prize == 0) & (plant.bloom == 0):
|
|
regular += 1
|
|
update = f"Plant types: {regular} regular, {flowering} flowering, "
|
|
update += f"{prize} prize flowers\n"
|
|
print(update)
|
|
|
|
|
|
class GardenManager:
|
|
def __init__(self):
|
|
self._garden: list[Garden] = []
|
|
|
|
def add_garden(self, garden: Garden) -> None:
|
|
self._garden.append(garden)
|
|
|
|
def garden_list(self) -> None:
|
|
result = "Garden scores"
|
|
len = 0
|
|
totalheight = 0
|
|
for Garden in self._garden:
|
|
for plant in Garden._plants:
|
|
Garden.score += plant.height
|
|
Garden.score += 10
|
|
if plant.bloom == 1:
|
|
Garden.score += 10
|
|
totalheight += plant.height
|
|
len += 1
|
|
result += f" - {Garden.owner}: {Garden.score}"
|
|
if (totalheight >= 200):
|
|
print("Height validation test: True")
|
|
else:
|
|
print("Height validation test: False")
|
|
print(result)
|
|
print(f"Total gardens managed: {len}")
|
|
|
|
|
|
print("=== Garden Management System Demo ===\n")
|
|
alice = Garden("Alice")
|
|
alice.add_plant(Plant("Oak Tree", 100, "", 0, 0))
|
|
alice.add_plant(Plant("Rose", 25, "red", 1, 0))
|
|
alice.add_plant(Plant("Sunflower", 50, "yellow", 0, 10))
|
|
|
|
Bob = Garden("Bob")
|
|
Bob.add_plant(Plant("Acacia Tree", 82, "", "", 0))
|
|
Manager = GardenManager()
|
|
Manager.add_garden(alice)
|
|
Manager.add_garden(Bob)
|
|
original = 0
|
|
original += alice.help_all_plants_grow()
|
|
alice.list_plants()
|
|
alice.list_update(original)
|
|
Manager.garden_list()
|