Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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 3.x - Fatal编程技术网

Python 国际单项体育联合会声明及;否则将无法正常工作

Python 国际单项体育联合会声明及;否则将无法正常工作,python,python-3.x,Python,Python 3.x,它总是让我心脏病发作 我是一个初学者,我想知道是否有其他方法可以做到这一点 最好每次都使用elif而不是if-else构造 if b1a == "rock": print("you gave him a concussion and made the rock your new weapon") weapon = "rock" else: print("you had a heart attack because you didn't pick one of th

它总是让我心脏病发作


我是一个初学者,我想知道是否有其他方法可以做到这一点

最好每次都使用
elif
而不是
if-else
构造

    if b1a == "rock":
    print("you gave him a concussion and made the rock your new weapon")
    weapon = "rock"
else:
    print("you had a heart attack because you didn't pick one of the options")
    exit()

if b1a == "NIGERUNDAYO":
    weapon = "tommy gun"
    print("You ran so much that the beast got tired, then you took out a tommy gun and started shooting")
else:
    print("you had a heart attack because you didn't pick one of the options")
    exit()

if b1a == "slash":
    print("you slashed his face with a hatchet. ")
else:
    print("you had a heart attack because you didn't pick one of the options")
    exit()

也许这个解决办法就足够了

试试看


您需要
elif
。如果您是初学者,那么在本例中,阅读一些关于Python的基本教程可能是一个非常好的主意。你似乎遇到的问题应该被他们和许多其他有用的东西所涵盖。
if b1a == "rock":
    print("you gave him a concussion and made the rock your new weapon")
    weapon = "rock"
elif b1a == "NIGERUNDAYO":
    weapon = "tommy gun"
    print("You ran so much that the beast got tired, then you took out a tommy gun and started shooting") 
elif b1a == "slash":
    print("you slashed his face with a hatchet. ")
else:
    print("you had a heart attack because you didn't pick one of the options")
    exit()
if b1a == "rock":
    print("you gave him a concussion and made the rock your new weapon")
    weapon = "rock"

elif b1a == "NIGERUNDAYO":
    weapon = "tommy gun"
    print("You ran so much that the beast got tired, then you took out a tommy gun and started shooting")
    exit()

elif b1a == "slash":
    print("you slashed his face with a hatchet. ")

else:
     print("you had a heart attack because you didn't pick one of the options")
     exit()