# My number guess code is not working properly

#1

Whenever I press enter into the terminal, it says “The maximum value is 12. No higher than the maximum” but it skips the “guess a number” part. Help appreciated, thanks.

"""Welcome to the Number Guess game. Pick a number and see who wins!"""

from random import randint
from time import sleep

def get_user_guess():
guess = int(raw_input("Guess a number!"))
return guess
# NOS stands for number of sides
def roll_dice(NOS):
first_roll = randint(1, NOS)
second_roll = randint (1, NOS)
max_val = NOS * 2
print "The maximum value is %d" % max_val
guess = get_user_guess
if guess > max_val:
print "No higher than the MAXIMUM!!"
else:
print "Rolling..."
sleep(2)
print "The 1st roll is: %d" % first_roll
sleep(1)
print "The 2nd roll is: %d" % second_roll
sleep(1)
total_roll = first_roll + second_roll
print "The total value is: %d" % total
print "Result..."
sleep(5)
if guess == total:
print "Good job! You won!"
else:
print "You lose"

roll_dice(6)

#2

#3

I’ve been trying for hours to figure out what is wrong.

#4

Sorry, it was my first time posting a comment.

#5

Forget previous answer lol… Look at your guess variable in the roll_dice method and look where it’s bound to. You forgot something

And also, while it is not part of your question, please look at the variable total … you forgot something

Hope this helps

#6

I included the def function to the get_user_guess and I changed the total variable but it still doesn’t work.

#7
from random import randint
from time import sleep

def get_user_guess():
guess = int(raw_input("Guess a number!"))
return guess
# NOS stands for number of sides
def roll_dice(NOS):
first_roll = randint(1, NOS)
second_roll = randint (1, NOS)
max_val = NOS * 2
print "The maximum value is %d" % max_val
guess = get_user_guess // <--------------- ***** include () after get_user_guess
if guess > max_val:
print "No higher than the MAXIMUM!!"
else:
print "Rolling..."
sleep(2)
print "The 1st roll is: %d" % first_roll
sleep(1)
print "The 2nd roll is: %d" % second_roll
sleep(1)
total_roll = first_roll + second_roll // <--------------- **** your variable is total_roll
print "The total value is: %d" % total   //<----------- **** make sure your variable names are the same
print "Result..."
sleep(5)
if guess == total:  //<-------------- **** same here
print "Good job! You won!"
else:
print "You lose"

roll_dice(6)

#8

You should bind guess to user_input_guess() … you forgot the parentheses.

The total variables should be total_roll.

Makes sure everything is the same

#9

Thank you very much, it works now.

#10

Thank you very much. If this forum allowed me to select two solutions, I would do that.

#11

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