|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 菜de嚣张 于 2022-11-12 17:10 编辑
- x = int(input("请输入一个正整数:"))
- if x < 0 or x != 0 and (x % 10 == 0):
- print("不是回文数。")
- else:
- revertedNumber = 0
- while x > 0:
- revertedNumber = revertedNumber * 10 + x % 10
- x //= 10
- if x == revertedNumber:
- print("是回文数。")
- else:
- print("不是回文数。")
复制代码
- if x < 0 or x != 0 and (x % 10 == 0):
复制代码
and 的优先级高于 or
- if x < 0 or (x != 0 and (x % 10 == 0)) :
- x = 12321 , x != 0 为 True,x % 10 == 0 为 False,所以,x != 0 and (x % 10 == 0) 为 False
- x < 0 为 False,x != 0 and (x % 10 == 0) 为 False,if x < 0 or x != 0 and (x % 10 == 0) 为 False
复制代码
|
|