# Number_Guess Game

#1

Nothing happening when I run the code. On bash, there is nothing; no comment, no correction. I think I made a loop but I don't know where.

``````"""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()``````

#2

Hi Dilann,

I found some errors with your code.

on lines 12 and 13 you mispelled randint, the lines should be
12 - first_roll = randint(1, number_of_sides)
13 - second_roll = randint(1, number_of_sides)
on line 40 you have roll_dice() indented and with no paramater specifed for # of sides, the line should be unindented
40 - roll_dice(6)
on line 10 you have return user_guess() but don't have user_guess() as a function, the line should be
10 - return(user_guess)
on lines 15 and 21 you have max_value and max_val, you need to modify one or the other to be the same
15 OR 21 - change max_value to max_val or vice versa so both lines read the same variablle

let me know if you have any trouble with these changes, or any questions
-Jared

#3

I fixed the code with your help. Thank you very much.

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.