Last active
June 9, 2020 11:09
-
-
Save nick3499/1ed1af0608944fd34e09c8805bad6a65 to your computer and use it in GitHub Desktop.
Python3: Random dice roll results
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
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run the following args to test the script locally in CLI:
$ curl -s https://gist.githubusercontent.com/nick3499/1ed1af0608944fd34e09c8805bad6a65/raw/78015d33339f11e413e7087fbc180aba5e82a1bc/roll_dice.py | python3