push
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
def check_plant_health(plant_name, water_level, sunlight):
|
||||
if not plant_name:
|
||||
raise ValueError("Plant name cannot be empty!")
|
||||
|
||||
if water_level < 1:
|
||||
raise ValueError(f"Water level {water_level} is too low (min 1)")
|
||||
if water_level > 10:
|
||||
raise ValueError(f"Water level {water_level} is too high (max 10)")
|
||||
|
||||
if sunlight < 2:
|
||||
raise ValueError(f"Sunlight hours {sunlight} is too low (min 2)")
|
||||
if sunlight > 12:
|
||||
raise ValueError(f"Sunlight hours {sunlight} is too high (max 12)")
|
||||
|
||||
return f"Plant '{plant_name}' is healthy!"
|
||||
|
||||
|
||||
def test_plant_checks():
|
||||
print("=== Garden Plant Health Checker ===")
|
||||
|
||||
print("\nTesting good values...")
|
||||
try:
|
||||
print(check_plant_health("tomato", 10, 5))
|
||||
except ValueError as e:
|
||||
print("Error:", e)
|
||||
|
||||
print("\nTesting empty plant name...")
|
||||
try:
|
||||
print(check_plant_health("", 10, 5))
|
||||
except ValueError as e:
|
||||
print("Error:", e)
|
||||
|
||||
print("\nTesting bad water level...")
|
||||
try:
|
||||
print(check_plant_health("tomato", 15, 5))
|
||||
except ValueError as e:
|
||||
print("Error:", e)
|
||||
|
||||
print("\nTesting bad sunlight hours...")
|
||||
try:
|
||||
print(check_plant_health("tomato", 10, 0))
|
||||
except ValueError as e:
|
||||
print("Error:", e)
|
||||
|
||||
print("\nAll error raising tests completed!")
|
||||
|
||||
|
||||
test_plant_checks()
|
||||
Reference in New Issue
Block a user