if __name__ == "__main__":
- name: str = "Rose"
+ print("=== Welcome to My Garden ===")
+ name: str = "rose"
height_cm: int = 25
age_days: int = 30
- print(f"Plant: {name}")
+ print(f"Plant: {name.capitalize()}")
print(f"Height: {height_cm}cm")
print(f"Age: {age_days} days")
+ print("\n=== End of Program ===")
+class Plant:
+ def __init__(self, name: str, height_cm: int, age_days: int) -> None:
+ self.name = name
+ self.height_cm = height_cm
+ self.age_days = age_days
+
+ def __repr__(self) -> str:
+ return (
+ f"{self.name.capitalize()}: "
+ + f"{self.height_cm}cm, "
+ + f"{self.age_days} days old"
+ )
+
+
+if __name__ == "__main__":
+ print("=== Garden Plant Registry ===")
+ rose = Plant("rose", 25, 30)
+ sunflower = Plant("sunflower", 80, 45)
+ cactus = Plant("cactus", 15, 120)
+ print(rose)
+ print(sunflower)
+ print(cactus)
--- /dev/null
+class Plant:
+ def __init__(self, name: str, height_cm: int, age_days: int) -> None:
+ self.name = name
+ self.height_cm = height_cm
+ self.age_days = age_days
+
+ def __repr__(self) -> str:
+ return (
+ f"{self.name.capitalize()}: "
+ + f"{self.height_cm}cm, "
+ + f"{self.age_days} days old"
+ )
+
+ def grow(self, by_cm: int):
+ self.height_cm += by_cm
+
+ def age(self, by_days: int):
+ # We assume a growth rate of 1cm per day
+ self.grow(by_days)
+ self.age_days += by_days
+
+
+if __name__ == "__main__":
+ print("=== Day 1 ===")
+ rose = Plant("rose", 25, 30)
+ initial_height = rose.height_cm
+ print(rose)
+ rose.age(6)
+ print("=== Day 7 ===")
+ print(rose)
+ print(f"Growth this week: +{rose.height_cm - initial_height}cm")
--- /dev/null
+class Plant:
+ def __init__(self, name: str, height_cm: int, age_days: int) -> None:
+ self.name = name
+ self.height_cm = height_cm
+ self.age_days = age_days
+
+ def __repr__(self) -> str:
+ return (
+ f"{self.name.capitalize()}: "
+ + f"{self.height_cm}cm, "
+ + f"{self.age_days} days old"
+ )
+
+ def grow(self, by_cm: int):
+ self.height_cm += by_cm
+
+ def age(self, by_days: int):
+ # We assume a growth rate of 1cm per day
+ self.grow(by_days)
+ self.age_days += by_days
+
+
+class PlantFactory:
+ def __init__(self):
+ self.plants = []
+
+ def create(self, name: str, height_cm: int, age_days: int) -> Plant:
+ plant = Plant(name, height_cm, age_days)
+ print(
+ f"Created: {plant.name.capitalize()} "
+ f"({plant.height_cm}cm, {plant.age_days} days)"
+ )
+ self.plants += [plant]
+ return plant
+
+
+if __name__ == "__main__":
+ print("=== Plant Factory Output ===")
+ factory = PlantFactory()
+ factory.create("rose", 25, 30)
+ factory.create("oak", 200, 365)
+ factory.create("cactus", 5, 90)
+ factory.create("sunflower", 80, 45)
+ factory.create("fern", 15, 120)
+ print(f"\nTotal Plants created: {len(factory.plants)}")