好吧,所以我还是不知道怎么回事(我遇到了一个奇怪的错误,我不得不编辑帖子并删除一些东西)这是我的代码,你知道为什么它不能工作吗?我试过很多东西,我不知道哪里出了问题。在
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()
您的函数名为
command
,您试图将输入读入名为command
的变量中。Python显然混淆了这两者,并试图在command
函数中搜索“Attack”,这是一个错误。在我建议您将输入变量重命名为
cmd
,然后看看问题是否会消失。在相关问题 更多 >
编程相关推荐