2013-07-20 15 views
8

ho scritto un programma per giocare boia --- non è finita, ma mi dà un errore per qualche motivo ...TypeError: 'int' oggetto non è invocabile ,,, 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" 

errore:

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

possibile duplicato di [TypeError: 'int' oggetto non è invocabile] (http://stackoverflow.com/questions/9767391/typeerror-int-object -is-non-callable) –

risposta

20

assegnato a un nome locale len:

len=len(word) 

Ora len è un numero intero e ombre l'ho costruito, n funzione. Si desidera utilizzare un nome diverso lì invece:

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

Altri suggerimenti:

  • Uso not luogo dei test per l'uguaglianza a False:

    while not n: 
    
  • Idem per i test per == True; questo è ciò che while già fa:

    while y: 
    
Problemi correlati