Created
January 7, 2019 05:32
-
-
Save shailrshah/1bcbef50e69d584b83fe057d178a8fc4 to your computer and use it in GitHub Desktop.
A program to simulate dice rolls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
class DiceRoller: | |
"""A DiceRoller instance is able to simulate dice rolls""" | |
def __init__(self, min=1, max=6): | |
self.min = min | |
self.max = max | |
print("Initialized. min is", min, "and max is", max) | |
def roll(self): | |
""" | |
Get a number in between self.min and self.max (both inclusive) | |
""" | |
return randint(self.min, self.max) | |
class Driver: | |
"""The driver for the dice roll program""" | |
def __init__(self): | |
self.dr = DiceRoller() | |
def run(self): | |
while True: | |
c = input("Do you want to roll the dice?") | |
if c == "Y": | |
print(self.dr.roll()) | |
else: | |
print("Thanks for visiting!") | |
break | |
d = Driver() | |
d.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment