From 4a538a844d9510a559d141f2cd20ec79b9eaffbc Mon Sep 17 00:00:00 2001 From: David Gailleton Date: Wed, 24 Dec 2025 14:05:01 +0000 Subject: [PATCH] 02/03 --- 02/ex3/ft_finally_block.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 02/ex3/ft_finally_block.py diff --git a/02/ex3/ft_finally_block.py b/02/ex3/ft_finally_block.py new file mode 100644 index 0000000..6673506 --- /dev/null +++ b/02/ex3/ft_finally_block.py @@ -0,0 +1,20 @@ +def water_plants(plant_list: []) -> None: + for plant in plant_list: + if plant == None: + raise ValueError + print("Watering", plant) + + +def test_watering_system() -> None: + plants = ["tomato", "lettuce", "carrots", None] + try: + print("Opening watering system") + water_plants(plants) + except: + print("Error: Cannot water None - invalid plant!") + finally: + print("Closing watering system (cleanup)") + + +if __name__ == "__main__": + test_watering_system()