-4

my error is:

File "guessing_game.py", line 117, in <module>               
    game()                               
  File "guessing_game.py", line 78, in game              
    for guesses in range (0,NUMBER_OF_GUESSES):          
TypeError: 'int' object is not callable     

my code: (btw on my computer everything in the function has an extra indent my code just copied and pasted wrong)

import time
#It clears all the code you have left in the terminal
import os
os.system("clear")

def game():



#Import the random module so it can create the random number
import random
MIN_DESIRED_NUMBER = 100
print "what range of numbers do you want to guess in (keep in mind you need a minimum of 100 numbers to guess from and you only get a maximum of 20 guesses)"
range = input()
range = int(range)
DESIRED_NUMBER = int(range)
while DESIRED_NUMBER < MIN_DESIRED_NUMBER:
    print "Your desired number to guess from is to low"
    print "Please choose another Number that is bigger 100 or bigger"
    range = input()
    range = int(range)
    DESIRED_NUMBER = int(range)

if DESIRED_NUMBER > MIN_DESIRED_NUMBER:

#Generate the random number and store it
    answer = random.randint(0,DESIRED_NUMBER)


#Set number of guess's





MAX_GUESS = 20


#set winner to false
winner = 0


print "The aim of the game is to guess a number between 1 and %s. How many guess would you like to have? (you are only allowed a maximum of 20 guesses)" % (DESIRED_NUMBER)
number = input()
number = int(number)
NUMBER_OF_GUESSES = int(number)
while NUMBER_OF_GUESSES > MAX_GUESS:
    print "Your desired number of guesses is to high"
    print "Please choose another Number that is 20 or less"
    number = input()
    number = int(number)
    NUMBER_OF_GUESSES = int(number)

if NUMBER_OF_GUESSES < MAX_GUESS:



#Print Completed instructions 

        print "You will now only have %s guesses to guess your number" % (NUMBER_OF_GUESSES)


    #Start the number loop of tries left
NUMBER_OF_GUESSES = int(number)
for I in range (0,NUMBER_OF_GUESSES):
    #Ask for number
    print "Please enter your guess"

    #Recive number and say if the number is hight or lower

    guess = input()
    #This converts guess from the text into an integer and the stores it again
    guess = int(guess)
    if guess > answer:
        print "Your number is to high"
    elif guess < answer:    
        print "Your answer is to low" 
    elif guess == answer:
        print "YAY YOU GOT THE ANSWER"
        winner = 1
        break


    #Stop loop if number is correct


#Say that the number was 
if winner == 0:
    print "You have used all of your guesses"
print "The number was %s" % (answer)


print "would you like to play again? (0/1)"
redo = int(input())
if redo == 1:
    game()
    os.system("clear")
elif redo==0:
    print "alright bye!!!"
time.sleep(3)
os.system("clear")

game()

Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67
Bob Trumen
  • 11
  • 1
  • You need to fix your indentation. – Morgan Thrapp Oct 07 '15 at 13:17
  • 1
    Don't put in random text to beat the filter. It's there for a reason; if it's complaining, it's because you didn't put in enough explanation for your question. – Daniel Roseman Oct 07 '15 at 13:18
  • As @DanielRoseman pointed out you have overridden you range function but you should be using xrange() if you are using 2.7. its [better](http://stackoverflow.com/questions/94935/what-is-the-difference-between-range-and-xrange-functions-in-python-2-x) and in 3.3 range was changed to be the same as xrange(). – SirParselot Oct 07 '15 at 13:20

1 Answers1

5

You've overridden the name range by using it as a variable name. Don't do that.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • when you mean i have overridden the range function do you mean that that is already a command in python and it just dosent recoognize it so i just need to change the variable (sorry im new to python) – Bob Trumen Oct 07 '15 at 13:22
  • 1
    @BobTrumen it doesn't really matter that it's *"already a command in Python"* - you have the same problem if you defined your own function then shadow it by assigning something else to the same name. It would have been fine to use `range`, as long as you *didn't then try to call that function* - names in Python can only refer to one object at a time. – jonrsharpe Oct 07 '15 at 13:25