python中的逻辑运算
逻辑运算
- 与(and)列出的多个条件同时满足
- 或(or) 列出的多个条件满足其中的任意一个条件
- 非(not) 列出的条件不满足
and运算符示例
age = int(input("请输入实际年龄:\n"))
if age >= 0 and age <= 120: # 这条语句可以简化为 if 0 <= age <= 120:print("年龄输入正确!")
else :print("输入有误,请重新输入有效数字!")
or运算符示例
python_score = int(input("请输入python的得分:"))
c_score = int(input("请输入c的得分:"))
if python_score > 60 or c_score > 60:print("成绩合格!")
else:print("请准备补考!")
not运算符示例
is_employee = int(input("请输入1或0:"))
if not is_employee == 1:print("非本公司员工,请勿入内!")
else:print("身份验证通过,请进!")