Skip to content

Instantly share code, notes, and snippets.

@nick3499
Last active June 9, 2020 11:09
Show Gist options
  • Save nick3499/1ed1af0608944fd34e09c8805bad6a65 to your computer and use it in GitHub Desktop.
Save nick3499/1ed1af0608944fd34e09c8805bad6a65 to your computer and use it in GitHub Desktop.
Python3: Random dice roll results
#! /bin/python3
'''`roll_dice` module contains `roll_dice` method which returns random \
results of two rolled dice.'''
from random import randrange
def roll_dice():
'''`roll_dice()` method returns random results of two dice.'''
die_segments = {
'top' : '┌───────┐',
'left' : '│ ● │',
'middl' : '│ ● │',
'right' : '│ ● │',
'both' : '│ ● ● │',
'none' : '│ │',
'bottm' : '└───────┘',
'space' : ' '}
die_builds = [
(''),
('none', 'middl', 'none'),
('left', 'none', 'right'),
('left', 'middl', 'right'),
('both', 'none', 'both'),
('both', 'middl', 'both'),
('both', 'both', 'both')]
def roll():
print(f"{die_segments['space']}\n{die_segments['top']}")
for seg in die_builds[randrange(1, 7, 1)]:
print(die_segments[seg])
print(die_segments['bottm'])
roll() # die 1
roll() # die 2
# more dice can be added
if __name__ == '__main__':
roll_dice() # if standalone
@nick3499
Copy link
Author

nick3499 commented Apr 30, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment