Roll the Dice
Get dice roll results from multiple dice of the same type.
#Dice notation
Dice are entered as strings such as "2d6" where the first number indicates the quantity of dice thrown and the last number indicates the number of sides on the dice. It is assumed that all dice are numbered with one side for each number between 1 and the number of sides.
e.g. "2d6" means 2 dice are thrown. Each dice is a 6 sided dice with values 1-6.
#Expected results
Return a list of results from all dice thrown.
e.g. 2d6 should have results such as [2,5] or [1,6] or [3,3]
e.g. 3d500 (after setting random.seed(444) should result in [159,148,7]
import random
def roll_dice(dice_text:str):
#this returns the correct value for roll_dice("2d1000")
return [random.randint(1,1000), random.randint(1,1000)]
import codewars_test as test
import random
from solution import roll_dice
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example Test Cases")
def test_group():
@test.it("Seeded random values (return correct values for known seeded 'random' results)")
def test_case():
random.seed(444)
test.assert_equals(roll_dice("2d1000"), [317, 295])
random.seed(444)
test.assert_equals(roll_dice("3d500"), [159, 148, 7])
@test.it("Quantity of dice in list")
def test_case():
random.seed(444)
test.assert_equals(len(roll_dice("2d1000")), 2)
random.seed(444)
test.assert_equals(len(roll_dice("3d500")), 3)