python - 触发不同结果的 Python 用户输入
问题描述
我是 Python 的初学者,所以请耐心等待 :)
我正在编写一个程序,我需要用户输入以根据输入内容触发不同的响应。这基本上就是我所拥有的(不完全是 b/c 我有一些计时的东西,但我怀疑有必要看看。)
resp = input()
if "yes" in resp:
print("resp1 is yes")
else:
print("resp1 is no")
resp2 = input()
if "no" in resp2:
print("resp2 is no")
else:
print("resp2 is yes")
但如果答案是否定的,我需要这个有不同的回应。现在,即使用户输入“否”,它也会转到应该属于第一个响应的答案,在这种情况下是“是”,而不是转到“否”。
我该如何解决这个问题?
谢谢 - (如果这没有任何意义,我很抱歉,如果你需要,我可以尝试更好地解释!)
陨石坑
解决方案
我可能对您的问题感到有些困惑,但是通过适当的缩进,它对我有用。它应该如下所示:
resp = input()
if "yes" in resp:
print('whatever the yes answer is')
resp2 = input()
if "no" in resp2:
print('whatever the no answer is')
推荐阅读
- flutter - 处理 AlertBox Flutter
- pyspark - 处理 pyspark 中的 JSON 模式更改
- django - ValueError:无法分配:必须是实例
- r - 在 R 中使用异常值创建多个异常值图和数据框
- python - 将宽转换为长,但重复特定列
- c# - 从 math.net 到数组的矩阵
- excel - 网站搜索失败时如何处理运行时错误 424?
- html - 在标记小说时,我应该使用多个 p 元素还是一个带有 br 元素的 p 元素?
- internet-explorer - 字体行高IE浏览器兼容性问题
- hibernate - 使用带有通用 Java 编程的 Quarkus Panache 实体时出错