Number Guess Function not defined


Please help me to understand the problem. This is the code:

Preformatted text

""""The program should do the following:
Roll a pair of dice.
Add the values of the roll.
Ask the user to guess a number.
Compare the user's guess to the total value.
Determine the winner (user or computer).

from random import randint
from time import sleep

def get_user_guess():
  guess = int(raw_input("Gues a number:"))
  return 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 possible value is: %d" % max_val
    guess = get_user_guess()
    if guess > max_val:
      print "No guessing higher than the maximum possible value!"
      print 'Rolling ...'
      print "First roll is: %d" % first_roll
      print "Second roll is: %d" % second_roll
      total_roll = first_roll + second_roll
      print "Total roll is: %d" % total_roll
      print "Result..."
      if guess == total_roll:
        print "You won!"
        print "You lost"


And this is what I get:

Traceback (most recent call last):
File “”, line number 40, in roll_dice(6)
Name Error: name ‘roll_dice’ is not defined


the roll_dice function is nested with your get_user_guess function, why?


Oh, thank you! I finally see where the mistake is. Everything is working perfectly now :slight_smile:


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