菜鸟IT的博客 >> Python
if语句中的多个条件 | 多个if判断合成一个总列表,再进行判断 | 类似if语句的or效果,至少满足多个if条件中的一个就行!
math_points = 51
biology_points = 78
physics_points = 56
history_points = 72
my_conditions = [math_points > 50, biology_points > 50,physics_points > 50,history_points > 50]
if all(my_conditions):
print("Congratulations! You have passed all of the exams.")
else:
print("I am sorry, but it seems that you have to repeat at least one exam.")
# 输出结果
# Congratulations! You have passed all of the exams.
# +————————————————————————————————
math_points = 40
biology_points = 78
physics_points = 56
history_points = 72
my_conditions = [math_points > 50, biology_points > 50,
physics_points > 50, history_points > 50]
if any(my_conditions):
print("Congratulations! You have passed all of the exams.")
else:
print("I am sorry, but it seems that you have to repeat at least one exam.")
# 输出结果
# Congratulations! You have passed all of the exams.
菜鸟IT博客[2022.10.23-17:27] 访问:490
※※相关信息专题※※
§【python技巧】