Number_Guess Game


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.

Please help me!

"""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)
  user_guess = get_user_guess()
  if user_guess > max_value:
    print "No guess can be higher than the maximum value. "
    print "Rolling..."
    sleep (2)
    print "The first value is %d" % (first_roll)
    print "The second value is %d" % (second_roll)
    total_roll = first_roll + second_roll
    print "Result... "
    if user_guess > total_roll:
        print "You Won !!"
        print "I Won !!"


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


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


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