mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-14 05:06:55 +01:00
FIX: every exercices of module 02
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
def check_plant_health(plant_name, water_level, sunlight_hours):
|
||||
def check_plant_health(plant_name: str, water_level: int, sunlight_hours: int) -> None:
|
||||
if not plant_name or not plant_name[0]:
|
||||
raise ValueError("Error: Plant name cannot be empty")
|
||||
elif water_level < 1:
|
||||
@@ -13,24 +13,29 @@ def check_plant_health(plant_name, water_level, sunlight_hours):
|
||||
print("Plant '" + plant_name + "' is healthy!")
|
||||
|
||||
|
||||
def test_plant_checks():
|
||||
def test_plant_checks() -> None:
|
||||
print("=== Garden Plant Health Checker ===")
|
||||
print("\nTesting good values...")
|
||||
try:
|
||||
check_plant_health("tomato", 5, 5)
|
||||
except ValueError as err:
|
||||
print(err)
|
||||
print("\nTesting bad water level...")
|
||||
try:
|
||||
check_plant_health("salade", 0, 5)
|
||||
except ValueError as err:
|
||||
print(err)
|
||||
print("\nTesting bad sunlight hours...")
|
||||
try:
|
||||
check_plant_health("carrots", 5, 20)
|
||||
except ValueError as err:
|
||||
print(err)
|
||||
print("\nTesting empty plant name...")
|
||||
try:
|
||||
check_plant_health("", 5, 5)
|
||||
except ValueError as err:
|
||||
print(err)
|
||||
print("All error raising tests completed!")
|
||||
print("\nAll error raising tests completed!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user