Python 入門指南 5.0
exercise2510.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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # 從 exercise2503 引入 DiceUser from exercise2503 import DiceUser # 從 exercise2504 引入 DiceGame from exercise2504 import DiceGame # 從 exercise2506 引入 DiceGame from exercise2506 import dice_game # 執行部分 if __name__ == '__main__': # 玩家名稱 names = ["小明", "小美", "小黑", "小愛"] # 詢問使用者是否要參加遊戲 user = input("請問要參與遊戲嗎?輸入暱稱或按 Enter 鍵跳過") if user != "": # 詢問使用者是否要當莊家 check_banker = input("請問是否要當莊家?輸入 Y 或 y 或按 Enter 鍵跳過") if check_banker == "Y" or check_banker == "y": names.insert(0, user) else: names.append(user) # 詢問遊戲的骰子數量 dice_number = input("請問骰子數量按 Enter 鍵跳過") match dice_number: case "1": dice_number = 1 case "2": dice_number = 2 case "3": dice_number = 3 case "4": dice_number = 4 case _: dice_number = 2 # 詢問使用者參加人數 check_number = input("請問 AI 玩家人數或按 Enter 鍵跳過") if user != "": match check_number: case "": dice_game(names, dice_number) case "1": dice_game(names[0:2], dice_number) case "2": dice_game(names[0:3], dice_number) case "3": dice_game(names[0:4], dice_number) case _: print(check_number + "錯誤設定") else: match check_number: case "": dice_game(names, dice_number) case "2": dice_game(names[0:2], dice_number) case "3": dice_game(names[0:3], dice_number) case "4": dice_game(names[0:4], dice_number) case _: print(check_number + "錯誤設定") # 檔名: exercise2510.py # 說明:《Python入門指南》的練習 # 網站: http://kaiching.org # 作者: 張凱慶 # 時間: 2023 年 10 月 |