TypeError:'int'对象不可调用,,, len()

时间:2013-07-20 12:20:36

标签: python python-2.7 int

我写了一个玩刽子手的程序---它还没有完成,但由于某种原因它给了我一个错误......

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"

错误:

    leenghthp=len(p)
TypeError: 'int' object is not callable

1 个答案:

答案 0 :(得分:28)

您已分配到本地名称len

len=len(word)

现在len是一个整数并隐藏内置函数。你想在那里使用不同的名称:

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

其他提示:

  • 使用not代替测试False的相等性:

    while not n:
    
  • 同样可以测试== True;这就是while已经做的

    while y: