首页 > 解决方案 > 如果条件为真,我们如何让python运行代码,如果条件为假,则运行另一个代码

问题描述

在这段代码中,我想知道如果 first_input == c 条件为真,则不应执行剩余的代码(在条件后提及),而应执行另一个代码(未提及),如果条件为假,则代码(提到的一个)应该被执行,另一个(未提到的)不应该被执行如果没有提到其他代码

first_input = input()
if first_input == a:
    print("something")
elif first_input == b:
    print("Another")
elif first_input == c:
second_input = input()
if second_input == d:
    print("done")

标签: python-3.x

解决方案


即使您的问题不是很清楚,您也应该尝试以下方法:

first_input = input()
if first_input == a:
    print("something")
elif first_input == b:
    print("Another")
elif first_input == c:
    #call your over function/code not mentioned here 
second_input = input()
if second_input == d:
    print("done")

它会做你想做的工作。


推荐阅读