Completed 9-13 Dice
This commit is contained in:
parent
766472d311
commit
7ed65078a8
29
Chapter_09/9-13_dice.py
Normal file
29
Chapter_09/9-13_dice.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Exercise 9-13 Dice
|
||||
# Learning Objective: Utilize the standard library module randint.
|
||||
|
||||
from random import randint
|
||||
|
||||
class Die:
|
||||
def __init__(self, sides=6):
|
||||
"Initialize a die with however many sides"
|
||||
self.sides = int(sides)
|
||||
|
||||
def roll_die(self):
|
||||
"""Generate random number given the range, output result"""
|
||||
print(f"This die has {self.sides} sides.\nRolling:")
|
||||
result = randint(1, self.sides)
|
||||
print(f"RESULT: {result}")
|
||||
|
||||
six_sider = Die()
|
||||
|
||||
six_sider.roll_die()
|
||||
|
||||
ten_sider = Die(10)
|
||||
|
||||
ten_sider.roll_die()
|
||||
|
||||
twenty_sider = Die(20)
|
||||
|
||||
twenty_sider.roll_die()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user