'max_val' not defined for step 16 (it's been 3 days working on this code)



Stuck on project 4 already had to take all the 'return' out just so it would run, but now I'm getting :

'NameError: name 'max_val' is not defined'

for line 17 and at this point, I literally copied and pasted from the hint. (I know, it's not learning, but it's shipping)

I've created the variable on line 13, so I'm not sure what else I could do.

### this is a game where the computer is going to 'roll' dice and the users have to guess the number###

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 = randint(1, number_of_sides)
    second_roll = randint(1, number_of_sides)
    max_val = number_of_sides * 2
    print "The maximum value you can guess is: " + str(max_val)
user_guess = get_user_guess()
if user_guess > max_val :
###this ^^^ is where I keep getting the error###
	print "That answer is no dice because it's more than the possible number."
	print "Rolling ...(the dice)...."
print "The first roll value is: %d" % first_roll
print "The second dice says: %d" % second_roll
total_roll= first_roll + second_roll
print "The result..."
if user_guess > total_roll:
	print "Winner, winner, chicken dinner! You win...this time."
  print "No dice. Sorry!"



Variables created in functions are local to that function unless global (which you shouldn't do) and you're not calling that function so it wouldn't be created anyway.


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