TypeError:'int'对象不可调用,,, len() [英] TypeError: 'int' object is not callable,,, len()

查看:175
本文介绍了TypeError:'int'对象不可调用,,, 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"

错误:

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


推荐答案

您已分配到本地名称 len

len=len(word)

现在 len 是一个整数并遮蔽内置功能。你想在那里使用不同的名称:

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

其他提示:


  • 使用而不是而不是测试相等于 False

while not n:


  • 同样用于测试 == True ;这就是,而已经

    while y:
    


  • 这篇关于TypeError:'int'对象不可调用,,, len()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆