网络编程
位置:首页>> 网络编程>> Python编程>> Python多分支if语句的使用

Python多分支if语句的使用

作者:良雨  发布时间:2022-07-17 17:52:54 

标签: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('全票')
#最后输出全票

来源:https://blog.csdn.net/qq_34821198/article/details/90596918

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com