1. 代码明细.
#逻辑运算符 and
#"10" or "0" 结果为10
# "" or "0" 结果为0
x = int(input("请输入数据:") or "0" )
if 0<=x<=100:
print("输入的数据合法")
if x >=0 and x<=100:
print("输入的数据合法")
2.具体操作.
tarena@tedu:~/桌面$ python3 and.py
请输入数据:
输入的数据合法
输入的数据合法
3.代码说明.
此次代码只有一个非常细小的进步,就是,如果输入空字符,不会在报错了,而代码中用到了or 操作符.
4.others
tarena zhuhairui 2018.7.7 20:27xinfangcun
![](https://img.haomeiwen.com/i11322958/d8a03db98a672078.jpg)
网友评论