Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'int' object is not callable,,, len()

I wrote a program to play hangman---it's not finished but it gives me an error for some reason...

import turtle
n=False
y=True
list=()
print ("welcome to the hangman! you word is?")
word=raw_input()
len=len(word)
for x in range(70):
    print
print "_ "*len
while n==False:
    while y==True:
        print "insert a letter:"
        p=raw_input()
        leenghthp=len(p)
        if leengthp!=1:
            print "you didnt give me a letter!!!"
        else:
            y=False
    for x in range(len):
        #if wo
        print "done"

error:

    leenghthp=len(p)
TypeError: 'int' object is not callable
like image 822
Gilad Wharton Kleinman Avatar asked Jul 20 '13 12:07

Gilad Wharton Kleinman


People also ask

How do I fix int object is not callable?

But in Python, this would lead to the Typeerror: int object is not callable error. To fix this error, you need to let Python know you want to multiply the number outside the parentheses with the sum of the numbers inside the parentheses. Python allows you to specify any arithmetic sign before the opening parenthesis.

How do I fix float object is not callable?

The “TypeError: 'float' object is not callable” error is raised when you try to call a floating-point number as a function. You can solve this problem by ensuring that you do not name any variables “float” before you use the float() function.

How do you fix a tuple object is not callable?

The Python "TypeError: 'tuple' object is not callable" occurs when we try to call a tuple as if it were a function. To solve the error, make sure to use square brackets when accessing a tuple at a specific index, e.g. my_tuple[0] .

What does it mean in Python when float object is not callable?

To summarize, TypeError 'float' object is not callable occurs when you try to call a float as if it were a function. To solve this error, ensure any mathematical operations you use have all operators in place. If you multiply values, there needs to be a multiplication operator between the terms.


1 Answers

You assigned to a local name len:

len=len(word)

Now len is an integer and shadows the built-in function. You want to use a different name there instead:

length = len(word)
# other code
print "_ " * length

Other tips:

  • Use not instead of testing for equality to False:

    while not n:
    
  • Ditto for testing for == True; that is what while already does:

    while y:
    
like image 162
Martijn Pieters Avatar answered Sep 20 '22 21:09

Martijn Pieters