當我嘗試運行此代碼時,出現語法錯誤,但未說明它是什麼行。我不知道我能說些什麼..這裏是代碼,獲得誤差位:當我嘗試運行此代碼時,出現語法錯誤
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