Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 6, 2017 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/1a3dbb98b63cb41757feadb80df30bb1 to your computer and use it in GitHub Desktop.
Save codecademydev/1a3dbb98b63cb41757feadb80df30bb1 to your computer and use it in GitHub Desktop.
Codecademy export
#this program is meant to play a game where the user guesses a number greater than the total value of the dice roll, if they do, they win
from random import randint
from time import sleep
def get_user_guess():
user_guess = int(raw_input("Guess a number buddy"))
return user_guess
roll_dice()
def roll_dice(number_of_sides):
first_roll = randint(1, number_of_sides)
second_roll = randint(1, number_of_sides)
max_val = number_of_sides * 2
print "The maximum possible value is drumrollllll please" + str(max_val)
sleep(1)
user_guess = get_user_guess()
if user_guess > max_val:
print "Your guess is not valid"
return
else:
print "Rolling"
sleep(2)
print "The first value is... %d !" % first_roll
sleep (1)
print "The second value is... %d !" % second_roll
total_roll = first_roll + second_roll
print total_roll
print "Result..."
sleep(1)
if user_guess > total_roll:
print "You are much luckier than I friend, well played"
return
else:
print "You lost, try again"
return
roll_dice(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment