Skip to content

Instantly share code, notes, and snippets.

@shailrshah
Created January 7, 2019 05:32
Show Gist options
  • Save shailrshah/1bcbef50e69d584b83fe057d178a8fc4 to your computer and use it in GitHub Desktop.
Save shailrshah/1bcbef50e69d584b83fe057d178a8fc4 to your computer and use it in GitHub Desktop.
A program to simulate dice rolls
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