Corrected ex1, ready to push

This commit is contained in:
2026-01-29 12:18:19 +01:00
parent 6c5ddeebf0
commit acc6d274c2
7 changed files with 279 additions and 111 deletions

View File

@@ -3,28 +3,35 @@ class Plants:
height: int
days: int
def __init__(self, name, height, days):
def __init__(self, name: str, height: int, days: int) -> None:
"""Init plant with his value"""
self.name = name
self.height = height
self.days = days
def get_info(self):
print(self.name.capitalize() + ":", self.height, end="")
print("cm,", self.days, "days old")
def get_info(self) -> None:
"""Display plant informations"""
print(self.name, ": ", self.height,
"cm, ", self.days, " days old", sep="")
def grow(self):
def grow(self) -> None:
"""Increase height"""
self.height = self.height + 1
def age(self):
def age(self) -> None:
"""Increase days by one and grow plant"""
self.days = self.days + 1
self.grow()
if __name__ == "__main__":
x = Plants("rose", 25, 1)
start = x.days;
x = Plants("rose", 25, 30)
start = x.days
print("=== Day 1 ===")
x.get_info()
for n in range(1, 8):
for n in range(1, 7):
x.age()
print(f"=== Day {x.days - start + 1} ===")
x.get_info()
print("Growth this week: +", x.days - start, "cm");
print("Growth this week: +",
x.days - start, "cm", sep="")