push
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
def ft_garden_intro():
|
||||
print("=== Welcome to My Garden ===")
|
||||
print("Plant: Rose\nHeight: 25cm\nAge: 30 days\n\n=== End of Program ===")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ft_garden_intro()
|
||||
@@ -0,0 +1,18 @@
|
||||
class Plant:
|
||||
def __init__(self, name, heigt, age):
|
||||
self.name = name
|
||||
self.heigt = heigt
|
||||
self.age = age
|
||||
|
||||
|
||||
def ft_garden_data():
|
||||
rose = Plant("Rose: ", 25, 30)
|
||||
Sunflower = Plant("Sunflower: ", 80, 45)
|
||||
Cactus = Plant("Cactus: ", 15, 120)
|
||||
print("=== Garden Plant Registry ===")
|
||||
print(rose.name, rose.heigt, "cm,", rose.age, "days old")
|
||||
print(Sunflower.name, Sunflower.heigt, "cm,", Sunflower.age, "days old")
|
||||
print(Cactus.name, Cactus.heigt, "cm,", Cactus.age, "days old")
|
||||
|
||||
|
||||
ft_garden_data()
|
||||
@@ -0,0 +1,23 @@
|
||||
class Plant:
|
||||
def __init__(self, name, heigt, age):
|
||||
self.name = name
|
||||
self.heigt = heigt
|
||||
self.age = age
|
||||
|
||||
|
||||
def get_info(rose):
|
||||
print(rose.name, rose.heigt, "cm,", rose.age, "days old")
|
||||
|
||||
|
||||
def ft_plant_growth():
|
||||
rose = Plant("Rose", 25, 30)
|
||||
print("=== Day 1 ===")
|
||||
get_info(rose)
|
||||
rose.heigt += 6
|
||||
rose.age += 6
|
||||
print("=== Day 7 ===")
|
||||
get_info(rose)
|
||||
print("Growth this week: +6cm")
|
||||
|
||||
|
||||
ft_plant_growth()
|
||||
@@ -0,0 +1,22 @@
|
||||
class Plant:
|
||||
def __init__(self, name, height, age):
|
||||
self.name = name
|
||||
self.height = height
|
||||
self.age = age
|
||||
|
||||
|
||||
plant_data = [
|
||||
("Rose", 25, 30),
|
||||
("Oak", 200, 365),
|
||||
("Cactus", 5, 90),
|
||||
("Sunflower", 80, 45),
|
||||
("Fern", 15, 120)
|
||||
]
|
||||
|
||||
index = 0
|
||||
plants = [Plant(name, height, age) for name, height, age in plant_data]
|
||||
|
||||
for p in plants:
|
||||
print(f"Created: {p.name} ({p.height} cm, {p.age} days)")
|
||||
index += 1
|
||||
print(f"\nTotal plants created: {index}")
|
||||
@@ -0,0 +1,34 @@
|
||||
class Plant:
|
||||
def __init__(self, name, height, age):
|
||||
self.name = name
|
||||
self.height = height
|
||||
self.age = age
|
||||
|
||||
|
||||
rose = Plant("Rose", 10, 15)
|
||||
|
||||
|
||||
def get_height(self):
|
||||
print("Invalid operation attempted: ")
|
||||
print(f"height {self.height}cm [REJECTED]")
|
||||
print("Security: Negative height rejected\n")
|
||||
|
||||
|
||||
def get_age(self):
|
||||
print(f"Invalid operation attempted: {self.age} days [REJECTED]")
|
||||
print("Security: Negative age rejected")
|
||||
|
||||
|
||||
def ft_garden_security():
|
||||
print("=== Garden Security System ===")
|
||||
if rose.height < 0:
|
||||
get_height(rose)
|
||||
if rose.age < 0:
|
||||
get_age(rose)
|
||||
if rose.age >= 0 & rose.height >= 0:
|
||||
print(f"Plant created: {rose.name}")
|
||||
print(f"Height updated: {rose.height}cm [OK]")
|
||||
print(f"Age updated: {rose.age} days [OK]")
|
||||
|
||||
|
||||
ft_garden_security()
|
||||
@@ -0,0 +1,44 @@
|
||||
class Plant:
|
||||
def __init__(self, name, height, age):
|
||||
self.name = name
|
||||
self.height = height
|
||||
self.age = age
|
||||
self.type = type
|
||||
|
||||
|
||||
class Tree(Plant):
|
||||
def __init__(self, name, height, age, type, diameter, shade):
|
||||
super().__init__(name=name, height=height, age=age)
|
||||
self.diam = diameter
|
||||
self.shade = shade
|
||||
self.type = type
|
||||
|
||||
|
||||
class Flower(Plant):
|
||||
def __init__(self, name, height, age, type, color, bloom):
|
||||
super().__init__(name=name, height=height, age=age)
|
||||
self.color = color
|
||||
self.bloom = bloom
|
||||
self.type = type
|
||||
|
||||
|
||||
class Vegetable(Plant):
|
||||
def __init__(self, name, height, age, type, season, nutrional):
|
||||
super().__init__(name=name, height=height, age=age)
|
||||
self.season = season
|
||||
self.nutrional = nutrional
|
||||
self.type = type
|
||||
|
||||
|
||||
r = Flower("Rose", 25, 30, "Flower", "red", "blooming")
|
||||
o = Tree("Oak", 500, 1825, "Tree", 50, 78)
|
||||
t = Vegetable("Tomato", 80, 90, "Vegatable", "summer",
|
||||
"vitamin C")
|
||||
|
||||
print("=== Garden Plant Types ===\n")
|
||||
print(f"{r.name} ({r.type}): {r.height}cm, {r.age} days, {r.color} color")
|
||||
print(f"{r.name} is {r.bloom} beautifully !\n")
|
||||
print(f"{o.name} ({o.type}): {o.height}cm, {o.age} days, {o.diam}cm diameter")
|
||||
print(f"{o.name} provides {o.shade} square meters of shade\n")
|
||||
print(f"{t.name} ({t.type}): {t.height}cm, {t.age} days, {t.season} harvest")
|
||||
print(f"{t.name} is rich in {t.nutrional}")
|
||||
@@ -0,0 +1,105 @@
|
||||
class Plant:
|
||||
def __init__(self, name, height, color, bloom, Prize):
|
||||
self.name = name
|
||||
self.height = height
|
||||
self.color = color
|
||||
self.bloom = bloom
|
||||
self.Prize = Prize
|
||||
|
||||
def grow(self, heigt: int = 1) -> None:
|
||||
self.height += heigt
|
||||
print(f"{self.name} grew {heigt}cm")
|
||||
|
||||
|
||||
class Garden:
|
||||
def __init__(self, owner: str):
|
||||
self.owner = owner
|
||||
self._plants: list[Plant] = []
|
||||
self.score = 0
|
||||
|
||||
def add_plant(self, plant: Plant) -> None:
|
||||
self._plants.append(plant)
|
||||
print(f"Added {plant.name} to {self.owner}'s garden")
|
||||
|
||||
def help_all_plants_grow(self) -> int:
|
||||
print(f"\n{self.owner} is helping all plants grow...")
|
||||
count = 0
|
||||
for plant in self._plants:
|
||||
plant.grow(1)
|
||||
count += 1
|
||||
return (count)
|
||||
|
||||
def list_plants(self) -> None:
|
||||
print(f"\n=== {self.owner}'s Garden Report ===")
|
||||
print("Plants in garden:")
|
||||
for plant in self._plants:
|
||||
display = f"- {plant.name}: {plant.height}cm"
|
||||
if (plant.color != ""):
|
||||
display += f", {plant.color} flowers"
|
||||
if (plant.bloom == 1):
|
||||
display += " (blooming)"
|
||||
if (plant.Prize > 0):
|
||||
display += f", Prize point: {plant.Prize}"
|
||||
print(display)
|
||||
|
||||
def list_update(self, height) -> None:
|
||||
regular = 0
|
||||
flowering = 0
|
||||
prize = 0
|
||||
print(f"\nPlants added: {len(self._plants)}, Total growth: {height}cm")
|
||||
for plant in self._plants:
|
||||
if plant.bloom == 1:
|
||||
flowering += 1
|
||||
if plant.Prize > 0:
|
||||
prize += 1
|
||||
if (plant.Prize == 0) & (plant.bloom == 0):
|
||||
regular += 1
|
||||
update = f"Plant types: {regular} regular, {flowering} flowering, "
|
||||
update += f"{prize} prize flowers\n"
|
||||
print(update)
|
||||
|
||||
|
||||
class GardenManager:
|
||||
def __init__(self):
|
||||
self._garden: list[Garden] = []
|
||||
|
||||
def add_garden(self, garden: Garden) -> None:
|
||||
self._garden.append(garden)
|
||||
|
||||
def garden_list(self) -> None:
|
||||
result = "Garden scores"
|
||||
len = 0
|
||||
totalheight = 0
|
||||
for Garden in self._garden:
|
||||
for plant in Garden._plants:
|
||||
Garden.score += plant.height
|
||||
Garden.score += 10
|
||||
if plant.bloom == 1:
|
||||
Garden.score += 10
|
||||
totalheight += plant.height
|
||||
len += 1
|
||||
result += f" - {Garden.owner}: {Garden.score}"
|
||||
if (totalheight >= 200):
|
||||
print("Height validation test: True")
|
||||
else:
|
||||
print("Height validation test: False")
|
||||
print(result)
|
||||
print(f"Total gardens managed: {len}")
|
||||
|
||||
|
||||
print("=== Garden Management System Demo ===\n")
|
||||
alice = Garden("Alice")
|
||||
alice.add_plant(Plant("Oak Tree", 100, "", 0, 0))
|
||||
alice.add_plant(Plant("Rose", 25, "red", 1, 0))
|
||||
alice.add_plant(Plant("Sunflower", 50, "yellow", 0, 10))
|
||||
|
||||
Bob = Garden("Bob")
|
||||
Bob.add_plant(Plant("Acacia Tree", 82, "", "", 0))
|
||||
Manager = GardenManager()
|
||||
Manager.add_garden(alice)
|
||||
Manager.add_garden(Bob)
|
||||
original = 0
|
||||
original += alice.help_all_plants_grow()
|
||||
alice.list_plants()
|
||||
alice.list_update(original)
|
||||
Manager.garden_list()
|
||||
Reference in New Issue
Block a user