Number Guess Function not defined


#1

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!"
    else:
      print 'Rolling ...'
      sleep(2)
      print "First roll is: %d" % first_roll
      sleep(1)
      print "Second roll is: %d" % second_roll
      total_roll = first_roll + second_roll
      print "Total roll is: %d" % total_roll
      print "Result..."
      sleep(1)
      if guess == total_roll:
        print "You won!"
      else:
        print "You lost"

roll_dice(6)

And this is what I get:

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


#2

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


#3

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


#4

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