# Learning Python "Number Guess" Freeform Project

#1

<In what way does your code behave incorrectly? Include ALL error messages.>
When I type in "python NumberGuess.py to the display screen and hit enter, nothing happens. I’m not sure what I’m doing wrong.

<What do you expect to happen instead?>
I am supposed to be at first told the max value that I can guess for a roll, but nothing happens.

``````

"""This program will randomly 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, decide a winner, and inform the user who won """
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)
mas_val = number_of_sides * 2
print "The maximum value is: " + str(max_val)
sleep(1)
user_guess = get_user_guess
if user_guess > max_value:
print "Think before you type"
return
else:
print "Rolling..."
sleep(2)
print "The first value is: %d" % first_roll
sleep(1)
total_roll = first_roll + second_roll
print "Result..."
sleep(1)
if user_guess > total_roll:
print "You have beat me, for now"
return
else:
print "No mere human can beat me"
return

roll_dice(6)
``````

Any help would be great!

#2

a function only execute when called

You do call the function, but from inside the function. You need to call the function directly from the main part of the program (outside/after the function)

#3

What do you mean by calling a function? I’m still pretty new at this so I don’t know the vocabulary very well. Thanks!

#4

And there was no possibility you could find this online somewhere or in an earlier exercise?

Functions are just a set of instructions to be completed. Its sort of like a task list, things which need doing. But you haven’t actually done them, in order to do so, you need to execute the task list. In programming, this achieved by calling the function:

``````# function call
roll_dice(6)
``````

#5

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