summaryrefslogtreecommitdiff
path: root/py01/ex3/ft_plant_factory.py
diff options
context:
space:
mode:
Diffstat (limited to 'py01/ex3/ft_plant_factory.py')
-rwxr-xr-xpy01/ex3/ft_plant_factory.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/py01/ex3/ft_plant_factory.py b/py01/ex3/ft_plant_factory.py
new file mode 100755
index 0000000..15669af
--- /dev/null
+++ b/py01/ex3/ft_plant_factory.py
@@ -0,0 +1,43 @@
+#!/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 height(self: 'Plant') -> None:
+ self.height_is *= 1.04
+
+# Method to show the plant information
+ def show(self: 'Plant') -> None:
+ print(self.name_is + ": " + str(round(self.height_is, 1)) + "cm, "
+ + str(self.age_is) + " days old")
+
+
+Params = [("Rose", 25, 30),
+ ("Oak", 200, 365),
+ ("Cactus", 5, 90),
+ ("Sunflower", 80, 45),
+ ("Fern", 15, 120)]
+
+
+def ft_plant_factory() -> None:
+ print("=== Plant Factory Output ===")
+ for param in Params:
+ obj = Plant(param[0], param[1], param[2]) # instantiate the object
+ # obj = Plant(*param) # instantiate the object and unpack with *
+ print("Created: ", end='')
+ obj.show()
+
+
+if __name__ == "__main__":
+ ft_plant_factory()