first = int(input('first int: '))
second = int (input('second int: '))
result =0
if first and second:
result =1
elif not first:
result =2
elif first or second:
result=3
else:
result=4
print(result)
当我输入 1 和 0 时,结果是 3。如果有人可以添加一些解释,我将不胜感激。
最佳答案
您使用的是or
- 这意味着该语句在第一次找到True
时将返回True
。
当您说 5 或 9
时,5 和 9 都代表真理(任何非零值也是如此)。所以在这种情况下它返回第一个 - 5。当您输入 9 或 5
时,它会返回 9。
编辑:k = 1 或 0
的计算结果为 True
,因为 1 代表真理。因此,根据您的代码,结果
是3
关于python - 需要帮助来理解 python 中的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21670749/