2016-12-02 9 views
1

私は、Pythonに新たなんだ、私は他のコードを見て、私はこのエラーを取得する方法、鉱山から「NoneType」エラー

tutorial = input("Do you want to do the tutorial? 1 is yes and 0 is no, this will be the same for everything") 
if tutorial <1: 
    print("That isn't valid") 
if tutorial>0: 
    print("That isn't valid") 
if tutorial == 1: 
    print("In battle you can use either sword, magic or items. Sword damage will be between your minimum and maximum damage, magic will be constant and can be used to heal or attack, items can be used to boost attack, restore health or armour") 

をnonetypeエラーを取り除く見当がつかないました:

Traceback (most recent call last): 
    File "<string>", line 250, in run_nodebug 
    File "C:\Users\Bas\Desktop\Game.py", line 50, in <module> 
    tutorial = input("Do you want to do the tutorial? 1 is yes and 0 is no, this will be the same for everything") 
TypeError: 'NoneType' object is not callable 

HERESにフルコード:

playerhealth = 100 
playerlow = 10 
playerhigh = 30 
playerarmour = 50 
playermagic = 20 
level = 0 
xptonextlevel = 200 
itemuse = 0 

rookhealth = 100 
rooklow = 10 
rookhigh = 20 
rookarmour = 100 

medichealth = 150 
mediclow = 10 
medichigh = 30 
medicarmour = 50 

rushhealth = 20 
rushlow = 10 
rushhigh = 10 
rusharmour = 30 

drillerhealth = 30 
drillerlow = 50 
drillerhigh = 80 
drillerarmour = 20 

dragonhealth = 200 
dragonlow = 150 
dragonhigh = 250 
dragonarmour = 150 
dragonmagic = 100 
dragonl = 45 

godhealth = 300 
godlow = 250 
godhigh = 350 
godarmour = 250 
godmagic = 200 
godl = 50 

magehealth = 100 
magearmour = 0 
magemagic = 50 
magel = 10 

tutorial = input("Do you want to do the tutorial? 1 is yes and 0 is no, this will be the same for everything") 
if tutorial <1: 
    print("That isn't valid") 
if tutorial>0: 
    print("That isn't valid") 
if tutorial == 1: 
    print("In battle you can use either sword, magic or items. Sword damage will be between your minimum and maximum damage, magic will be constant and can be used to heal or attack, items can be used to boost attack, restore health or armour") 

se = input("Input 1 for story or 0 for endless") 
+5

inputという変数がありますか? – Sayse

+1

あなたのコードは*すべて*ですか?なぜなら、あなたは 'input'関数に何かをしたに違いないようです。おそらく、コードの残りのどこかに入力を割り当てて、最終的に*組み込み*入力をシャドーイングしているかもしれません。 – idjaw

+0

@idjaw私はちょうどそれをすべて追加しました – Llione

答えて

1

識別子inputに値0123を割り当てられているため、このエラーを取得します。あなたのコードのどこかで、次の行が実行されていなければなりません。

input = None 

NoneTypeシングルトン定数Noneのタイプです。 あなたがこれを行うにしようとしている場合は、同じエラーが発生します。

>>> None("Do you want to do the tutorial?") 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'NoneType' object is not callable 

Pythonは新しい値で組み込み関数をオーバーライドするのを防ぐことはできません。場合によっては、関数printなどを再定義すると便利な場合もあります。しかし、通常の状況では、inputlistintなどを変数名として使用することは悪い考えです。これは、このようなバグを引き起こす可能性があるためです。

非常に長い変数リストを宣言するのではなく、辞書を使用して誤って識別子を上書きする可能性を減らすことができます。

gamestate = { 
    'playerhealth': 100, 
    'playerlow': 10, 
    'playerhigh': 30, 
    'input': None, 
    'else': 42, 
    ... 

シャドウイングの組み込みについて心配することなく、任意の文字列を辞書キーとして使用できます。

関連する問題