我正在尝试创建一个文本冒险游戏但是当我尝试运行它时,我在“battle_input = battle_input.lower()”和“if battle_input ==”攻击“:”时收到错误 你能告诉我什么错了吗?
def battle(monster):
print "You have encountered a %s" % (str(monster))
while hero_health > 0 or monster.health > 0:
battle_input = input("Would you like to attack, use magic, use item, or retreat?"
battle_input = battle_input.lower()
if battle_input == "attack":
print "You attack with your %s!" % (weapon)
damage = random.randint(hero_attack, player_attack + 5)
print "The %s takes %s damage!" % (monster, str(damage))
monster.health -= damage
if monster.health <= 0:
print "You slayed the %s!" % (monster)
break
#add the others
print "The %s attacks!" % (monster)
monster_damage = random.randint(monster.attack, monster.attack + 5)
player_health -= damage
else:
if monster_health <= 0:
print "Congratulations!"
else:
print "Game over."
game_over = 1
答案 0 :(得分:1)
您错过了前一行input
行的右括号:
battle_input = input("Would you like to attack, use magic, use item, or retreat?"
# ----------------^
添加右括号,Python可以理解这一行和下一行。
经验法则:每当遇到看似不合理的奇怪SyntaxError
时,检查前一行并确保所有左括号,括号和括号都有匹配的结束字符。