对,我在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