Python 入門指南 5.0
exercise2204.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 | # 從 exercise2201 引入 ParameterError
from exercise2201 import ParameterError
# 從 exercise2201 引入 higher
from exercise2202 import higher
# 從 random 引入 randint
from random import randint
# 執行部分
if __name__ == '__main__':
# 設定隨機答案
answer = randint(1, 99)
# 取得使用者輸入
try:
user_input = int(input("請輸入比較數字:"))
except ValueError:
print("型態轉換錯誤")
# 判斷使用者輸入是否合乎範圍
if 1 <= user_input <= 99:
print(higher(user_input, answer))
else:
print("輸入超出範圍")
# 檔名: exercise2204.py
# 說明:《Python入門指南》的練習
# 網站: http://kaiching.org
# 作者: 張凱慶
# 時間: 2023 年 10 月
|