​python_modules /
module-02 / ex0 / ft_first_exception.py
106 commits
09-05-2026
25 lines 594 B
 1def input_temperature(temp_str: str) -> int:
 2    return int(temp_str)
 3
 4
 5def test_temperature() -> None:
 6    print("=== Garden Temperature ===\n")
 7
 8    test_inputs = ["25", "abc"]
 9
10    for tmp in test_inputs:
11        print(f"Input data is '{tmp}'")
12
13        try:
14            temperature = input_temperature(tmp)
15            print(f"Temperature is now {temperature}°C")
16        except ValueError as error:
17            print(f"Caught input_temperature error: {error}")
18
19        print()
20
21    print("All tests completed - program didn't crash!")
22
23
24if __name__ == "__main__":
25    test_temperature()