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
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.
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.
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] .
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With