summaryrefslogtreecommitdiff
path: root/py02/ex0
diff options
context:
space:
mode:
authoryctct <yctct@yctct.com>2026-06-07 08:59:04 +0200
committeryctct <yctct@yctct.com>2026-06-07 08:59:04 +0200
commit15115b4c52bfda0d1cca9fa1155beecbb873ec35 (patch)
treeb3f0975e63eb04dcba732a78ce9bd9abda8acf01 /py02/ex0
First commit, add all files
Diffstat (limited to 'py02/ex0')
-rwxr-xr-xpy02/ex0/ft_first_exception.py27
1 files changed, 27 insertions, 0 deletions
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!")