Raw_input Function Not Working in Number Guess


I am working on the Number Guess project in Python, I can’t get the get_user_guess function to work, please take a look at my code, I can’t figure out what is wrong with it.

When I run the program it starts running, but never asks me for the input from the first function. It doesn’t give me an error code, just stops running because there is no user input.

I am expecting it to ask me for the guess. Any ideas on how to make this happen?

This program will roll a pair of dice, add the value of the roll, ask the user to guess a number, compare the user's guess to the total value, and determine if the computer of the user wins
from random import randint
from time import sleep

def get_user_guess():
  guess = int(raw_input("Guess 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 maxinum possible value is: %d" % max_val
  guess = get_user_guess
  if guess > max_val:
    print "Your guess is higher than the maximum value."
    print "Rolling..."
    print "Your first roll is: %d" % first_roll
    print "Your second roll is: %d" % second_roll
    total_roll = first_roll + second_roll
    print "Your total roll is: %d" % total_roll
    print "Result..."
    if guess > total_roll:
      print "You Won!"
      print "You lost, sorry..."




guess = get_user_guess

you attempt to call get_user_guess, but not correctly. As such the function isn’t called, you just created a variable also containing the function. Which we can see:

guess = get_user_guess
print guess


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