NameError:name' Atk'没有定义

时间:2016-02-21 03:21:38

标签: python python-2.7

好的,所以我仍然不知道发生了什么(我得到了一个奇怪的错误,我必须编辑帖子并删除内容)这里是我的代码,任何想法为什么它的不工作?我尝试了很多东西,我不确定是不是错了。

Traceback (most recent call last):
  File "C:/Users/tyler/Desktop/PycharmProjects/Arcade Game/AttackDirectory.py", line 111, in <module>
     Battle()
File "C:/Users/tyler/Desktop/PycharmProjects/Arcade Game/AttackDirectory.py", line 106, in Battle
command()
File "C:/Users/tyler/Desktop/PycharmProjects/Arcade Game/AttackDirectory.py", line 92, in command
cmd = input('What Will You Do?')
File "string", line 1, in <module>
NameError: name 'Atk' is not defined




    ThiefPdmg = (lambda x: (round(x*0.75)))(Thief['stats']['Attack'])

    ThiefMdmg = (lambda x: (round(x*0.75)))(Thief['stats']['Magic'])

    ThiefHP = Thief['stats']['HP']

    ImpDMG = (lambda x: (round(x*0.75 / Thief['lvl'] + 1)))(Imp['stats']['Attack'])

    ImpHP = Imp['stats']['HP']

    def Attack(Attacker, Defender):

AttackerDMG = ThiefPdmg
Defenderhp = Imp['stats']['HP']

print('You Attacked!')

    if Thief['stats']['Speed'] >= Imp['stats']['Speed']:
            ImpHP - ThiefPdmg

    if Imp['stats']['Speed'] > Thief['stats']['Speed'] :
            ThiefHP - ImpDMG

    if ImpHP <= 0:
            print('{} Was Killed!'.format(Imp['name']))


    def command():

cmd = input('What Will You Do?')

if 'Atk' in cmd:
    Attack()

else:
    Pass

    def Battle():

    Attackerhp = Thief['stats']['HP']
    Defenderhp = Imp['stats']['HP']

print('An imp appeared!')
print('                ')
while Defenderhp and Attackerhp > 0:
    command()

if Defenderhp <= Defenderhp:
    print('Took {} Damage!'.format(Enemy['name'], Dmg or Mdmg))

    Battle()

1 个答案:

答案 0 :(得分:1)

您的函数名为command,您尝试将输入读入名为command的变量。 Python显然让两者混淆,并试图搜索“攻击”。在command函数内,这是一个错误。

我建议您将输入变量重命名为cmd,并查看问题是否消失。

def get_command():
    action = input('What will you do? ').lower()
    if action == 'attack':
        Attack()
    else: 
        print("Wimp!")