mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-13 20:56:54 +01:00
Corrected ex1, ready to push
This commit is contained in:
@@ -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="")
|
||||
|
||||
Reference in New Issue
Block a user