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

新手上路,请多包涵

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

 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

原文由 Gilad Wharton Kleinman 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 785
2 个回答

您分配给本地名称 len

 len=len(word)

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

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

其他提示:

  • 使用 not 而不是测试是否等于 False
   while not n:

  • 同上测试 == True ;这就是 while 已经 _做的_:
   while y:

原文由 Martijn Pieters 发布,翻译遵循 CC BY-SA 3.0 许可协议

我的错误是我在代码的某处初始化了 len=0 。所以不要在关键字的名称上做变量

原文由 Roonal Khandelwal 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进