Editor

Roll the Dice

#515 · Modules and random · Beginner · 25 XP · about 4 min

Board games need dice, and the random module can roll them: random.randint(a, b) returns a random whole number from a to b, both included.

Write roll_dice(count, sides=6) that rolls count dice, each with its faces numbered from 1 to sides, and returns the results as a list in the order they were rolled.

Examples

roll_dice(5)      # returns a list such as [3, 6, 1, 1, 4]
roll_dice(3, 20)  # returns a list such as [17, 2, 9]
roll_dice(0)      # returns []

Note

The tests cannot know which numbers you will roll, so they check what must always be true: the number of rolls, that every roll is in range, and that every face turns up about equally often over many rolls.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.