python - 给定两个非零整数,如果恰好有一个为正数则打印 "YES"否则打印 "NO"(Python)

标签 python python-2.7

<分区>

第一次问关于stackoverflow的问题。我一直在努力解决这个问题。这是我的代码:

a = int(input()) 
b = int(input())

给定两个非零整数,如果恰好有一个为正数则打印“YES”,否则打印“NO”。

if (a > 0) or (b > 0):
    print('YES') 
else:
    print('NO')

最佳答案

if (a>0) != (b>0):
    print("YES")
else:
    print("NO")

How do you get the logical xor of two variables in Python?

关于python - 给定两个非零整数,如果恰好有一个为正数则打印 "YES"否则打印 "NO"(Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54775353/

相关文章:

jquery - Django JQuery 自动完成

python - 如何根据该行的第 1 列与该行的第 2 列相比大多少来给出某些行 'points'

Python2 : Resize image plotted using Matplotlib

python - Python 用于导入模块的顺序是什么?

Python 从配置文件中删除一个字符串

python - 需要从 Unix shell -> Python -> & 返回进行控制

python - Python 中不需要的空间

python - 在 Pillow 中确定带有换行符的字符串的像素高度

Python 生成器截止

python - 如何在 Python 中从 CSV 文件中提取 JSON 对象?