首页 > 解决方案 > 有没有办法让 While 函数具有两个条件?

问题描述

当我运行我的代码时,即使我输入 1 或 2,它也会运行。

我已经做过了while a != 1 or 2:while a != 1 or a !=2:

a = 0
while a != 1 or a !=2:
    a = int(input('Input: '))
print('end')

我想知道在不使用“break”方法的情况下使用两个条件中断的方式。

标签: python-3.x

解决方案


a不能同时是 1 和 2,所以这是一个无限循环:

while a != 1 or a != 2:

推荐阅读