TypeError: 'int' object is not callable,,, len()

前端 未结 1 1191
悲&欢浪女
悲&欢浪女 2021-02-19 01:39

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 h         


        
1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-19 02:25

    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:
      

    0 讨论(0)
提交回复
热议问题