blob: f0c7a7bdfbe0db313bc04143e9198202b8404105 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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!")
|