mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-01-27 01:01:59 +00:00
02/03
This commit is contained in:
20
02/ex3/ft_finally_block.py
Normal file
20
02/ex3/ft_finally_block.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user