Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x Python 3.6 elif语法错误_Python 3.x_Syntax - Fatal编程技术网

Python 3.x Python 3.6 elif语法错误

Python 3.x Python 3.6 elif语法错误,python-3.x,syntax,Python 3.x,Syntax,使用嵌套的if语句和缩进看起来是正确的,但仍然会出现语法错误。谢谢 # FIGHT Dragons if ch3 in ['y', 'Y', 'Yes', 'YES', 'yes']: # WITH SWORD if sword == 1: print ("You only have a sword to fight with!") print ("You quickly jab the Dragon in it's chest and gain

使用嵌套的if语句和缩进看起来是正确的,但仍然会出现语法错误。谢谢

# FIGHT Dragons
if ch3 in ['y', 'Y', 'Yes', 'YES', 'yes']:

    # WITH SWORD
    if sword == 1:
        print ("You only have a sword to fight with!")
        print ("You quickly jab the Dragon in it's chest and gain an advantage")
        time.sleep(2)
        print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        print ("                  Fighting...                   ")
        print ("   YOU MUST HIT ABOVE A 5 TO KILL THE DRAGON    ")
        print ("IF THE DRAGON HITS HIGHER THAN YOU, YOU WILL DIE")
        print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        time.sleep(2)
        fdmg1 = int(random.randint(3, 10))
        edmg1 = int(random.randint(1, 5))
        print ("you hit a", fdmg1)
        print ("the dragon hits a", edmg1)
        time.sleep(2)

        if edmg1 > fdmg1:
            print ("The drgon has dealt more damage than you!")
            complete = 0
        return complete 
这就是我遇到语法错误的地方
elif fdmg1<5:
打印(“你没有造成足够的伤害杀死drgon,但你成功逃脱了”)
完成=1
返回完成
其他:
打印(“你杀了博士!”)
完成=1
返回完成

您的报税表必须位于if…elif…else语句的末尾。这项工作:

if edmg1 > fdmg1:
    print ("The drgon has dealt more damage than you!")
    complete = 0

elif fdmg1 < 5:
    print ("You didn't do enough damage to kill the drgon, but you manage to escape")
    complete = 1

else:
    print ("You killed the drgon!")
    complete = 1

return complete   
如果edmg1>fdmg1:
打印(“drgon造成的伤害比你大!”)
完成=0
elif fdmg1<5:
打印(“你没有造成足够的伤害杀死drgon,但你成功逃脱了”)
完成=1
其他:
打印(“你杀了博士!”)
完成=1
返回完成

请注意,如果第一个if条件为True,Python将不会检查后续的if条件。

上一行带有
返回
,似乎缩进不正确,因此留给您的是
elif
,没有匹配的
if
。可能是
if edmg1 > fdmg1:
    print ("The drgon has dealt more damage than you!")
    complete = 0

elif fdmg1 < 5:
    print ("You didn't do enough damage to kill the drgon, but you manage to escape")
    complete = 1

else:
    print ("You killed the drgon!")
    complete = 1

return complete