Skip to content

Instantly share code, notes, and snippets.

@mrspucches
Last active June 22, 2017 14:01
Show Gist options
  • Save mrspucches/aa6976fb1cdba823357123acd076a7e2 to your computer and use it in GitHub Desktop.
Save mrspucches/aa6976fb1cdba823357123acd076a7e2 to your computer and use it in GitHub Desktop.
Roll the dice against the computer!
import random
# Author: Dominic Spucches
# Date: 18 JUN 2017
# Project: Dice Game, asks if you want to play, generates random numbers. The program also says who won and if its a tie.
print("Hello! Would you like to play a game? Choose the number 1 for yes, and the number 2 for no!")
game = input('> ')
while True:
if game == '1':
print('Awesome you chose to play! We are going to roll dice against the computer!')
print("Type 'Roll' whenever you're ready to begin!")
roll = input('> ')
if roll.lower() == 'roll':
you = random.randrange(1, 6)
print('You rolled a', you, '!')
computer = random.randrange(1, 6)
print('The computer rolled a', computer, '!')
if you > computer:
print('You beat the the computer!')
elif computer > you:
print('You were beat by the computer!')
elif you == computer:
print('Looks like there was a tie!')
else:
print('Thank you for playing')
print("Do you want to play again? Type 'yes' to play again or type 'no' to quit.")
play_again = input('> ')
if play_again.lower() == 'yes':
print('Lets play again!')
else:
print('Ok! Sad to see you go! Come back again next time!')
quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment