Created
January 6, 2020 00:07
-
-
Save erj1/b33ecf9e838c0fe66c0034f3f93785f8 to your computer and use it in GitHub Desktop.
This file contains 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
import random | |
roll_again_options = ['y', 'yes'] | |
def roll_die(die_sides: int = 6): | |
return random.choice(range(1, die_sides + 1)) | |
if __name__ == '__main__': | |
# set the number of sides on the die | |
sides = input("How Many Sides Are On Your Die? (default: 6): ") or '6' | |
while not sides.isdigit(): | |
print('Please Enter A Whole Number') | |
sides = input("How Many Sides Are On Your Die?: ") | |
roll_again = 'Y' | |
while roll_again.lower() in roll_again_options: | |
roll = roll_die(int(sides)) | |
print(f"You rolled a {roll}.") | |
roll_again = input("Would you like to roll again? (Y/n): ") or 'Yes' | |
print("Thanks. Come Again Soon!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My answer to the dice rolling simulator found here: https://knightlab.northwestern.edu/2014/06/05/five-mini-programming-projects-for-the-python-beginner/
To run the code:
python dice_roll.py
I may want to adjust this to use a new different command-line tools like argparse, click or something similar.