對,我在python中創建了一個文本遊戲作爲我的第一個大項目,但我對我的語法感到困惑。它說無效的語法,但我可以看到其他任何東西。所有的幫助提前感謝。製作python文字遊戲無效的語法錯誤
def fight(playerhp, a1, a2, a3, a4, run, d1, d2, d3, d4, enemy, edamage, armor, attack, enemytype, reward):
print("OH NO YOUVE ENCOUNTERED " + enemy + "WHAT DO YOU DO?")
time.sleep(1)
while enemy > 0 and playerhp > 0:
attack = input("would you like to " + a1 + a2 + a3 + a4 + "or " + run)
if attack == a1:
enemy = enemy-d1
print("You dealt" + d1 + " damage! the enemy now has " + enemy + "HP!")
elif attack == a2:
enemy = enemy-d2
print("You dealt" + d2 + " damage! the enemy now has " + enemy + "HP!")
elif attack == a3:
enemy = enemy - d3
print("You dealt" + d3 + " damage! the enemy now has " + enemy + "HP!")
elif attack == a4:
enemy = enemy-d4
print("You dealt" + d4 + " damage! the enemy now has " + enemy + "HP!")
print("the " + enemytype + "attacks! It deals " + edamage + " damage! you now have" + playerhp + "health!")
if enemy <=0:
print("the monster was slayn and the guts went everywhere :D. In its carcass you found " + reward + "gold!")
if playerhp <=0:
print("the monster de_stroyed you, and your blood will be painted in its lair.")
Traceback (most recent call last):
File "python", line 38
enemy = enemy - d1
^
SyntaxError: invalid syntax
您在上一行中缺少分號。應該是'if attack == a1:' – elethan
你在條件結尾的上面一行缺少一個冒號:如果攻擊== a1應該是如果攻擊== a1:。 – idjaw
@Brian Yeah,剛纔也注意到了!其中一些...其實...和父母... – elethan