這是一個簡單的擲骰子遊戲應用程序。 用戶可以指定要滾動的骰子數量以及每個骰子的麵數。然後應用程序模擬滾動並顯示結果。
這是 Python 中可能的實現:
import random
def roll_dice(num_dice, num_sides):
"""Simulates rolling multiple dice.
Args:
num_dice: The number of dice to roll.
num_sides: The number of sides on each die.
Returns:
A list of integers representing the results of each die roll. Returns an empty list if input is invalid.
"""
if num_dice
此應用程序提示用戶輸入骰子的數量和麵數。 然後,它使用 random.randint()
函數來模擬擲骰並顯示各個結果和擲骰的總和。 包含錯誤處理來管理無效輸入。 用戶可以通過輸入 0 作為骰子數量來退出應用程序。 這是一個基本示例,可以擴展以包括圖形用戶界麵或更複雜的遊戲機製等功能。
標籤 : 謎