Python 入門指南 5.0
exercise2410.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 29 30 31 32 33 34 35 | # 從 exercise2301 引入 Guess from exercise2301 import Guess # 從 exercise2304 引入 GuessUser from exercise2304 import GuessUser # 從 exercise2306 引入 GuessGame from exercise2306 import GuessGame def guess_game(name): g = GuessGame(name) check = "" count = 0 record = [] while True: count += 1 record.append(g.playgame()) check = input("按下 Enter 結束遊戲,或進行下一輪請輸入 y 或 Y :") if check == "y" or check == "Y": continue else: break print("共進行" + str(count) + "次遊戲") print("最多猜測" + str(max(record)) + "次") print("最少猜測" + str(min(record)) + "次") print("平均猜測次數為" + str(sum(record)/len(record)) + "次") # 執行部分 if __name__ == '__main__': user_input = input("請輸入暱稱:") guess_game(user_input) # 檔名: exercise2410.py # 說明:《Python入門指南》的練習 # 網站: http://kaiching.org # 作者: 張凱慶 # 時間: 2023 年 10 月 |