09-05-2026
34 lines
835 B
1class Plant:
2 def __init__(self, name: str, height: float, days_old: int) -> None:
3 self.name = name
4 self.height = height
5 self.days_old = days_old
6
7 def grow(self, growth_rate: float) -> None:
8 self.height += growth_rate
9
10 def age(self) -> None:
11 self.days_old += 1
12
13 def show(self) -> None:
14 print(f"{self.name}: {self.height:.1f}cm, {self.days_old} days old")
15
16
17def main() -> None:
18 rose = Plant("Rose", 25, 30)
19 oak = Plant("Oak", 200, 365)
20 cactus = Plant("Cactus", 5, 90)
21 sunflower = Plant("Sunflower", 80, 45)
22 fern = Plant("Fern", 15, 120)
23
24 plants = [rose, oak, cactus, sunflower, fern]
25
26 print("=== Plant Factory Output ===")
27
28 for plant in plants:
29 print("Created: ", end="")
30 plant.show()
31
32
33if __name__ == "__main__":
34 main()