diff options
| author | yctct <yctct@yctct.com> | 2026-06-07 08:59:04 +0200 |
|---|---|---|
| committer | yctct <yctct@yctct.com> | 2026-06-07 08:59:04 +0200 |
| commit | 15115b4c52bfda0d1cca9fa1155beecbb873ec35 (patch) | |
| tree | b3f0975e63eb04dcba732a78ce9bd9abda8acf01 /py01/ex2/ft_plant_growth.py | |
First commit, add all files
Diffstat (limited to 'py01/ex2/ft_plant_growth.py')
| -rwxr-xr-x | py01/ex2/ft_plant_growth.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/py01/ex2/ft_plant_growth.py b/py01/ex2/ft_plant_growth.py new file mode 100755 index 0000000..c516181 --- /dev/null +++ b/py01/ex2/ft_plant_growth.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +# Create a class +class Plant: + def __init__(self: 'Plant', name: str, height: float, age: int) -> None: + self.name_is = name + self.height_is = height + self.age_is = age + +# Method to grow the age + def age(self: 'Plant') -> None: + self.age_is += 1 + +# Method to grow the height + def grow(self: 'Plant') -> None: + self.height_is *= 1.04 + +# Method to show the plant information + def show(self: 'Plant') -> None: + print(f" {self.name_is}: {str(round(self.height_is, 1))}cm," + f"{str(self.age_is)} days old") + + +rose = Plant("Rose", 25, 30) + + +def ft_garden_growth(plant: Plant) -> None: + print("=== Garden Plant Growth ===") + plant.show() + start = plant.height_is + count = 7 + for i in range(1, count + 1): + print("=== Day " + str(i) + " ===") + plant.age() + plant.grow() + plant.show() + print("Growth this week: " + str(round(plant.height_is - start, 1)) + "cm") + + +if __name__ == "__main__": + ft_garden_growth(rose) |
