问题
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
回答1:
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 toFalse
:while not n:
Ditto for testing for
== True
; that is whatwhile
already does:while y:
来源:https://stackoverflow.com/questions/17762210/typeerror-int-object-is-not-callable-len