Skip to content

Instantly share code, notes, and snippets.

@erj1
Created January 6, 2020 00:07
Show Gist options
  • Save erj1/b33ecf9e838c0fe66c0034f3f93785f8 to your computer and use it in GitHub Desktop.
Save erj1/b33ecf9e838c0fe66c0034f3f93785f8 to your computer and use it in GitHub Desktop.
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!")
@erj1
Copy link
Author

erj1 commented Jan 6, 2020

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.

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