【发布时间】:2021-11-13 19:57:21
【问题描述】:
我是编程新手(例如非常新),我决定为我最喜欢的角色扮演游戏 Vampire the Masquerade 制作一个掷骰子。对于那些不知道的人,当你想在 VtM 中掷骰子时,你会做 d10s(十面骰子)的骰子池,然后你是否成功取决于你掷出的“成功”数量;任何骰子结果为 6 或更多。
到目前为止,我已经成功制作了一个可以滚动 d10s 的基本滚筒:
#"d" is the number of dice
def roll(d):
return [randint(1,10) for i in range(d)]
#Main Program
d = int(input("\nHow many dice are you rolling? > "))
results = roll(d)
print(results)
但是,我无法让程序计算卷中的成功次数。我希望输出看起来像
How many dice are you rolling? > 2
[5, 9]
1 success
有什么建议吗?
【问题讨论】:
-
successes = count(results, key=lambda die: die >= 6)