当我尝试运行此代码时,出现语法错误,但未说明它是什么行。我不知道我能说些什么..这里是代码,获得误差位:当我尝试运行此代码时,出现语法错误
if "q" in attack:
if random.randint(1,100) != range(1,21):
print("You hit with a quick attack!")
ehp -= 20
print("The",enam,"loses 20 damage! It now has",ehp,"health.")
else:
print("You missed.. :(")
elif "p" in attack:
if random.randint(1,100) != range(1,51):
print("You hit with a power attack!")
ehp -= 50
print("The",enam,"loses 50 damage! It now has",ehp,"health.")
else:
print("You missed.. :(")
elif "1" in attack:
if mana >= skill1[2]:
print("You hit with",skill1[0])
ehp -= skill1[1]
mana -= skill1[2]
print("The",enam,"loses",skill1[1],"damage! It now has",ehp,"health.")
print("You now have",mana,"mana.")
elif "2" in attack:
if mana >= skill2[2]:
print("You hit with",skill2[0])
ehp -= skill2[1]
mana -= skill2[2]
print("The",enam,"loses",skill2[1],"damage! It now has",ehp,"health.")
print("You now have",mana,"mana.")
elif "3" in attack:
if mana >= skill3[2]:
print("You hit with",skill3[0])
ehp -= skill3[1]
mana -= skill3[2]
print("The",enam,"loses",skill3[1],"damage! It now has",ehp,"health.")
print("You now have",mana,"mana.")
else:
print("You typed something wrong.")
顺便说一句,skill1,skill2和skill3是在比赛中我要作不同的技能所有列表技能1 [0]是技能的名称,技能[1]是技能的攻击力和技能[2]是用来使用技能的法力值。
skill1 = []
skill2 = []
skill3 = []
skill1.append("Very Weak Fireball")
skill1.append(20)
skill1.append(30)
skill2.append("Weak Fireball")
skill2.append(30)
skill2.append(40)
skill3.append("Average Fireball")
skill3.append(40)
skill3.append(50)
哪个语法错误?它通常给你的行号是错误的,这在这里会非常有用。但是既然你说的没有,确切的错误确实会变得更有趣 – 2015-02-07 10:07:50
请确保你正确地缩进了你的代码(第一个'if'语句) – vaultah 2015-02-07 10:09:06
请注意你的缩进.. – Olu 2015-02-07 10:14:12