我有一个 Python 作业如下:“编写一个完整的 python 程序,要求用户输入两个整数。如果两个整数都是even。否则程序输出 Not Both Even
。”
我计划使用 if 和 else 语句,但由于我要处理两个必须为偶数而不是一个的数字,我该怎么做呢?
如果是一个数字,我会这样做。现在如何添加用户输入的 second_int???
if first_int % 2 == 0:
print ("Both even")
else: print("Not Both Even")
最佳答案
您仍然可以使用 if else 并使用 if block 检查多个条件
if first_int % 2 == 0 and second_int % 2 == 0:
print ("Both even")
else:
print("Not Both Even")
关于python - 在 Python 中查找偶数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28390730/