Skip to content

Instantly share code, notes, and snippets.

@Leslie1207
Created July 14, 2014 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Leslie1207/a49478ee4e4f92a2291f to your computer and use it in GitHub Desktop.
Save Leslie1207/a49478ee4e4f92a2291f to your computer and use it in GitHub Desktop.
Dice rolling simulator
""" Dice rolling simulator, will ask user to press Enter to roll.
Will print a random number between 1 to 6. Will ask user if they want to roll again. """
import random
print "Welcome to the Dice Rolling Simulator!\n"
print "Press Enter to roll the dice."
begin = raw_input("")
""" function where random numbers are generated """
def dice_roll():
while True:
print "You have rolled..."
print random.randint(1,6)
print "and"
print random.randint(1,6)
break
print "\n"
""" ask whether player wants to roll the dice again. will only accept yes or no.
otherwise loops back. """
def roll_dice_again():
again = str(raw_input("Would you like to roll the dice again? 'Yes' or 'No'?\n").lower())
if again == "yes":
print "\n"
dice_roll()
roll_dice_again()
elif again == "no":
print "\n"
print "Thank you for playing."
else:
print "\n"
print "That is incorrect."
roll_dice_again()
dice_roll()
roll_dice_again()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment