Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在分配变量和冒号时出错_Python_Python 2.7 - Fatal编程技术网

Python 在分配变量和冒号时出错

Python 在分配变量和冒号时出错,python,python-2.7,Python,Python 2.7,我正在尝试制作一个文本冒险游戏,但当我尝试运行它时,我在“battle\u input=battle\u input.lower()”和“if battle\u input==”attack()上出现错误: 你能告诉我怎么了吗 def battle(monster): print "You have encountered a %s" % (str(monster)) while hero_health > 0 or monster.health > 0: battle_in

我正在尝试制作一个文本冒险游戏,但当我尝试运行它时,我在“battle\u input=battle\u input.lower()”和“if battle\u input==”attack()上出现错误: 你能告诉我怎么了吗

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
def战斗(怪物):
打印“您遇到了%s”%(str(怪物))
当英雄生命值>0或怪物生命值>0时:
battle_input=input(“你想攻击、使用魔法、使用道具还是撤退?”
battle\u input=battle\u input.lower()
如果作战输入==“攻击”:
打印“你用你的%s!攻击!”%(武器)
伤害=随机。随机(英雄攻击,玩家攻击+5)
打印“该%s受到%s伤害!”%(怪物,str(伤害))
怪物。生命-=伤害

如果monster.health在前面的
输入中缺少右括号
行:

battle_input = input("Would you like to attack, use magic, use item, or retreat?"
#                                                                ----------------^
添加右括号,Python可以理解这一行和下一行


经验法则:每当你遇到一个奇怪的
语法错误
,看起来没有意义时,检查前一行,确保所有的左括号、方括号和大括号都有一个匹配的结束字符。

前一行缺少
。使用
原始输入
而不是
输入