This commit is contained in:
lfirmin
2026-01-07 21:42:11 +01:00
parent d02ef5f88a
commit 11040c45b8
25 changed files with 572 additions and 3 deletions
@@ -0,0 +1,37 @@
class Plant:
def __init__(self, name, water):
self.name = name
self.water = water
tomato = Plant("tomato", 10)
lettuce = Plant("lettuce", 5)
carrots = Plant("carrots", 7)
def water_plants(plants_list):
print("Open watering system")
try:
for p in plants_list:
p.water += 1
print(f"Watering {p.name}")
except AttributeError:
print(f"Error: Cannot water {p} - invalid plant!")
else:
print("Watering completed successfully!")
finally:
print("Closing watering system (cleanup)")
def test_watering_system():
print("=== Garden Watering System ===")
plantlist = [tomato, lettuce, carrots]
badlist = [tomato, None, lettuce]
print("\nTesting normal watering...")
water_plants(plantlist)
print("\nTesting with error...")
water_plants(badlist)
print("\nCleanup always happens, even with errors!")
test_watering_system()