名称错误:未定义名称“Atk”

2024-10-06 11:37:23 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,所以我还是不知道怎么回事(我遇到了一个奇怪的错误,我不得不编辑帖子并删除一些东西)这是我的代码,你知道为什么它不能工作吗?我试过很多东西,我不知道哪里出了问题。在

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()

Tags: inifstatslineuserscommandfilehp
1条回答
网友
1楼 · 发布于 2024-10-06 11:37:23

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

我建议您将输入变量重命名为cmd,然后看看问题是否会消失。在

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

相关问题 更多 >