-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfinite_dice_roll_with_sides.py
29 lines (23 loc) · 1.03 KB
/
infinite_dice_roll_with_sides.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Dice game that rolls infinitely number of times until last rolled dice is not the number of sides of the dice.
"""
import random # generate random numbers
def roll_dice(sides: int) -> int:
"""
Rolls the dice with specified number of sides.
sides - the number of sides to roll.
"""
return random.randint(1, sides) # roll the dice with specified number of sides
def roll_and_multiply(sides: int) -> int:
"""
Rolls the dice infinite number of times until last rolled dice is not the number of sides of the dice, then multiply the rolled dice.
sides - the number of sides to roll.
"""
result = 1 # set result to 1
# roll the dice with specified number of sides of dice
roll: int = roll_dice(sides)
while roll == sides: # while rolled dies is not the number of sides of dice
result *= sides # multiply result by number of sides of dice
roll = roll_dice(sides) # roll the dice again
result *= roll # multiply result by last rolled dice
return result # return the result