18

ハングマンをプレイするプログラムを書きました --- 完成していませんが、何らかの理由でエラーが発生します...

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
4

1 に答える 1

49

ローカル名に割り当てましたlen:

len=len(word)

現在lenは整数であり、組み込み関数をシャドウします。代わりに別の名前を使用したい場合:

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

その他のヒント:

  • notと等しいかどうかをテストする代わりに使用しFalseます。

    while not n:
    
  • のテストについても同様です== True。それはwhileすでに行っていることです:

    while y:
    
于 2013-07-20T12:22:14.300 に答える