python-3.x - 如果条件为真,我们如何让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")
解决方案
即使您的问题不是很清楚,您也应该尝试以下方法:
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")
它会做你想做的工作。
推荐阅读
- python - 删除 Plotly Sankey 图中的文本标签,但在悬停时保留数据 [Plotly Python Sankey question]
- reactjs - 在 history.goback() 之后,React 组件没有加载道具
- c++ - 错误:'foo' 未被捕获 Lambda 函数和增强集成
- javascript - 为模板组件执行创建方法
- ubuntu - 如何在 Ubuntu 上安装 CUnit?
- arrays - 需要有关创建新对象以在比较后存储用户信息的指导
- r - 删除 geom_text_repel() 中的选定标签
- azure - 无法使用 Visual Studio 部署 WEB Api
- c++ - 英特尔 PIN 是否支持仅跟踪 .NET 可执行文件中的 JIT 代码?
- python-3.x - 如何使用 mplcursors 用多列注释