Skip to content

Instantly share code, notes, and snippets.

@khayyamsaleem
Created August 16, 2017 21:12
Show Gist options
  • Save khayyamsaleem/1c0b82914cfd306e40730fb7bcc878ed to your computer and use it in GitHub Desktop.
Save khayyamsaleem/1c0b82914cfd306e40730fb7bcc878ed to your computer and use it in GitHub Desktop.
"""This is a guessing game about rolling dice, summing the total and comparing to a guess. HOPKINS August 16th, 2017"""
from random import randint
from time import sleep
def get_user_guess():
user_guess = int(raw_input("Guess a number between 2 and 12"))
return user_guess
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 sum will be " + str(max_val)
sleep(1)
user_guess = get_user_guess()
if user_guess>max_val:
print "Your guess is too big"
else:
print "Rolling"
sleep(2)
print "Your first roll was a %d" % first_roll
sleep(1)
print "Your second roll was a %d" % second_roll
sleep(1)
total_roll = first_roll + second_roll
print "And the result is %d" % total_roll
sleep(1)
if user_guess>total_roll:
print "Hey dog, you won!"
return
elif user_guess<total_roll:
print "I'm sorry, you lost this round"
return
roll_dice(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment