在python中滚动5个骰子

时间:2016-11-19 03:03:00

标签: python python-3.x dice

我得到了:

    def rollDice(dice, toRoll=[0,1,2,3,4]):

        """Rolls specified dice. If no dice are specified, all dice are rolled."""
        for i in toRoll:
            dice[i] = random.randint(1,6)

对于我的生活,我无法弄清楚如何调用此功能来掷五个骰子。我尝试过rollDice(5,toRoll)和其他一些变种。我还有其他地方的回程线

2 个答案:

答案 0 :(得分:2)

作为一个作业问题,我想给你一个提示:

想想在函数中如何使用骰子:

  • for loop
  • 中为其分配了一个值
  • 使用整数i
  • 进行“索引”

使用this page作为参考,看看是否可以获得提示

答案 1 :(得分:1)

该函数写入其第一个参数。试试这个:

dice = [None] * 5
rollDice(dice)
print(dice)