Python 入門指南 5.0
exercise2202.py
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
28 | # 從 exercise2201 引入 ParameterError
from exercise2201 import ParameterError
# 比較兩個參數
def higher(first_number: int, second_number: int) -> bool:
try:
# 確認參數是整數
assert type(first_number) is int
assert type(second_number) is int
# 回傳參數比較結果
return first_number > second_number
except AssertionError:
# 回傳參數錯誤例外
raise ParameterError
# 執行部分
if __name__ == '__main__':
try:
print(higher(11, 10))
print(higher("1", 10))
except ParameterError as p:
print(p)
# 檔名: exercise2202.py
# 說明:《Python入門指南》的練習
# 網站: http://kaiching.org
# 作者: 張凱慶
# 時間: 2023 年 10 月
|