NumberGuess, nothing happens in terminal


#1

Nothing happens in terminal. It does not ask for a number, it does not print the mistake message,… nothing.

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 maximum value is %d" % max_val
  guess = get_user_guess()
  if guess > max_val:
    print "Invalid number"
  
  roll_dice(13)

#2

the function call executes the function, but the function call is never reached given its nested inside the function


#3

Sorry, I tried to copy the code, but it is not working. It is not inside the function, it is out.
I get several error messages now, saying the ‘int’ object is not callable. :sweat:

It looks like this:

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 is %d” % max_val
guess = get_user_guess()
if guess > max_val:
print "Invalid number, max value is 12. "
return
else:
print "Rolling… "
sleep(2)
print “The first roll is %d” % first_roll
sleep(1)
print “The second roll is %d” % second_roll
sleep(1)
total_roll = first_roll + second_roll
print “the total value is: %d” % total_roll
print "Result… "
sleep(1)
if guess == total_roll:
print “you won”
else:
print “you lost”

roll_dice(6)


#4

can you then paste the latest version of your code in a new reply?


#5

OMG, it “erases” all the indentations. Still trying to solve this… Oh, ok, let’s try one thing:

18


#6

and this is the error message I get:
26


#7

line 8, guess is an integer, but by adding parentheses, you attempt to call the integer? Integers aren’t callable like functions


#8

YAY!!! thanks so much, that was it! I guess I have tried so many changes looking at other’s people codes that I put it there at some point.


#9

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


#10