mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-01-27 01:01:59 +00:00
01 to 3 i think
This commit is contained in:
11
01/ex0/ft_garden_intro.py
Normal file
11
01/ex0/ft_garden_intro.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
if __name__ == "__main__":
|
||||||
|
name = "Rose"
|
||||||
|
height = "25"
|
||||||
|
age = "30"
|
||||||
|
|
||||||
|
print("=== Welcome to My Garden ===")
|
||||||
|
print("Plant:", name)
|
||||||
|
print("Height:", height, "cm")
|
||||||
|
print("Age:", age, "days")
|
||||||
|
print("")
|
||||||
|
print("=== End of Program ===")
|
||||||
23
01/ex1/ft_garden_data.py
Normal file
23
01/ex1/ft_garden_data.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
class Plants:
|
||||||
|
name: str
|
||||||
|
height: int
|
||||||
|
age: int
|
||||||
|
|
||||||
|
def __init__(self, name, height, age):
|
||||||
|
self.name = name
|
||||||
|
self.height = height
|
||||||
|
self.age = age
|
||||||
|
|
||||||
|
def print_plant(self):
|
||||||
|
print(self.name.capitalize() + ":", self.height, end="")
|
||||||
|
print("cm,", self.age, "days old")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
x = Plants("rose", 25, 30)
|
||||||
|
y = Plants("sunflower", 80, 45)
|
||||||
|
z = Plants("cactus", 15, 120)
|
||||||
|
print("=== Garden Plant Registry ===")
|
||||||
|
x.print_plant()
|
||||||
|
y.print_plant()
|
||||||
|
z.print_plant()
|
||||||
30
01/ex2/ft_plant_growth.py
Normal file
30
01/ex2/ft_plant_growth.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
class Plants:
|
||||||
|
name: str
|
||||||
|
height: int
|
||||||
|
p_age: int
|
||||||
|
|
||||||
|
def __init__(self, name, height, age):
|
||||||
|
self.name = name
|
||||||
|
self.height = height
|
||||||
|
self.p_age = age
|
||||||
|
|
||||||
|
def get_info(self):
|
||||||
|
print(self.name.capitalize() + ":", self.height, end="")
|
||||||
|
print("cm,", self.p_age, "days old")
|
||||||
|
|
||||||
|
def grow(self):
|
||||||
|
self.height = self.height + 1
|
||||||
|
|
||||||
|
def age(self):
|
||||||
|
self.p_age = self.p_age + 1
|
||||||
|
self.grow()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
x = Plants("rose", 25, 1)
|
||||||
|
x.get_info()
|
||||||
|
i = 1
|
||||||
|
while i < 8:
|
||||||
|
x.age()
|
||||||
|
i = i + 1
|
||||||
|
x.get_info()
|
||||||
0
01/ex3/ft_plant_factory.py
Normal file
0
01/ex3/ft_plant_factory.py
Normal file
Reference in New Issue
Block a user