我正在开展一个小型练习项目,但我找不到答案。我想滚动4d6,降低最低,然后将剩下的三个加在一起。我发现heapq.nlargest可以为我找到最高的N个数字,但是我无法弄清楚如何将其输出加到一个数字中。
到目前为止,我未完成的代码看起来像这样:
import random
import heapq
print "How many stats would you like to roll?"
dice = input
for i in range(dice()):
roll1 = random.randint(1, 6)
roll2 = random.randint(1, 6)
roll3 = random.randint(1, 6)
roll4 = random.randint(1, 6)
allrolls = (roll1, roll2, roll3, roll4)
high3 = heapq.nlargest(3, allrolls)
答案 0 :(得分:0)
high3sum = sum(high3)
答案 1 :(得分:0)