-
-
Save codecademydev/c0f5f886d90525eeaec90a80fe9788b4 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""number guessing game | |
computer vs human""" | |
from random import randint | |
from time import sleep | |
def get_user_guess(): | |
user_guess = int(raw_input("Guess a number... ")) | |
return user_guess() | |
def roll_dice(number_of_sides): | |
first_roll = ranint(1,number_of_sides) | |
second_roll = ranint(1,number_of_sides) | |
max_val = number_of_sides * 2 | |
print "The maximum value is: " + str(max_val) | |
sleep(1) | |
user_guess = get_user_guess() | |
if user_guess > max_value: | |
print "No guess can be higher than the maximum value. " | |
return | |
else: | |
print "Rolling..." | |
sleep (2) | |
print "The first value is %d" % (first_roll) | |
sleep(1) | |
print "The second value is %d" % (second_roll) | |
sleep(1) | |
total_roll = first_roll + second_roll | |
print "Result... " | |
sleep(1) | |
if user_guess > total_roll: | |
print "You Won !!" | |
else: | |
print "I Won !!" | |
roll_dice() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment