Skip to content

Instantly share code, notes, and snippets.

@emarte91 emarte91/Dice.py
Created Oct 26, 2018

Embed
What would you like to do?
Roll the dice against the computer. Highest number wins
import random
def roll():
option = input("Roll the dice! y/n:")
if option == 'y' or option == 'Y':
results()
def results():
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
ai_roll = dice1 + dice2
dice3 = random.randint(1, 6)
dice4 = random.randint(1, 6)
human_roll = dice3 + dice4
if human_roll > ai_roll:
print("You win! You rolled a {}, and the computer rolled a {}".format(human_roll, ai_roll))
restart()
elif human_roll == ai_roll:
print("It's a tie! Both rolled a {}".format(human_roll))
restart()
else:
print("You lose! You rolled a {} and the computer rolled a {}".format(human_roll, ai_roll))
restart()
def restart():
replay = input("Play again? y/n:")
if replay == 'y' or replay == "Y":
results()
else:
print("Thanks for playing")
roll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.