Python多分支if语句的使用
更新时间:2020年09月03日 09:19:13 作者:良雨
这篇文章主要介绍了Python多分支if语句的使用,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
注意:if语句代码是从上往下执行的,当执行到满足条件的语句时,代码会停止往下执行
注意:if语句后面要加上冒号
score = int (input("score:"))
if score > 90:
print("A")
elif score > 80:
print("B")
elif score > 70:
print("C")
elif score > 60:
print("D")
else score < 60:
print("加油吧孩纸")
补充知识:python之if语句以及条件测试( and 、or、in、not in)
1.and 、or、in、not in
'''
条件测试
'''
#单个条件测试
age0 = 22
print(age0>=22) # True
#多个条件测试 and
age0 = 22
age1 = 18
print(age0>=21 and age1>=21) #False
#多个条件测试 or
print(age0>=21 or arg0>=21) #True
#in和not in(检查特定值是否在列表中)
fruits = ['apple','banana','orange']
print('apple' in fruits) #True
print('apple' not in fruits) #False
2.if语句
'''
简单的if语句(仅包含一个测试和一个操作)
'''
height = 1.7
if height>=1.3:
print('高')
'''
if-else
'''
height = 1.8
if height<=1.4:
print('免票')
else:
print('全票')
#最后输出全票
'''
if-elif
'''
height = 1.5
if height>=1.4:
print('嘿嘿')
elif height>=1.3:
print('呵呵')
#最后输出嘿嘿
'''
if-elif-else
'''
height = 1.8
if height<=1.4:
print('免票')
elif height>1.4 and height<=1.7:
print('半票')
else:
print('全票')
#最后输出全票
以上这篇Python多分支if语句的使用就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Python实现对Excel文件中不在指定区间内的数据加以去除的方法
这篇文章主要介绍了基于Python语言,读取Excel表格文件,基于我们给定的规则,对其中的数据加以筛选,将不在指定数据范围内的数据剔除,保留符合我们需要的数据的方法,需要的朋友可以参考下2023-08-08
用python简单实现mysql数据同步到ElasticSearch的教程
今天小编就为大家分享一篇用python简单实现mysql数据同步到ElasticSearch的教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-05-05
Python解决IndexError: list index out of&nb
IndexError是一种常见的异常类型,它通常发生在尝试访问列表(list)中不存在的索引时,错误信息“IndexError: list index out of range”意味着你试图访问的列表索引超出了列表的实际范围,所以本文给大家介绍了Python成功解决IndexError: list index out of range2024-05-05


最新评论