From 15115b4c52bfda0d1cca9fa1155beecbb873ec35 Mon Sep 17 00:00:00 2001 From: yctct Date: Sun, 7 Jun 2026 08:59:04 +0200 Subject: First commit, add all files --- py02/ex0/ft_first_exception.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 py02/ex0/ft_first_exception.py (limited to 'py02/ex0') diff --git a/py02/ex0/ft_first_exception.py b/py02/ex0/ft_first_exception.py new file mode 100755 index 0000000..f0c7a7b --- /dev/null +++ b/py02/ex0/ft_first_exception.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# https://docs.python.org/3/tutorial/errors.html#handling-exceptions + +def input_temperature(temp_str: str) -> int: + print(f" Input data is '{temp_str}'") + tested_value = test_temperature(temp_str) + return tested_value + + +def test_temperature(temp): + try: + temp = int(temp) + except ValueError as ve: + print(" Caught input_temperature error:", ve) + else: + print(f" Temperature is now {temp}°C") + return temp + + +if __name__ == "__main__": + print("=== Garden Temperature ===") + print() + input_temperature("25") + print() + input_temperature("abc") + print() + print(" All tests completed - program didn't crash!") -- cgit v1.2.3