Python多分支if语句的使用

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

注意: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

标签:Python,多分支,if语句
0
投稿

猜你喜欢

  • Ubuntu 16.04 LTS中源码安装Python 3.6.0的方法教程

    2021-10-19 05:05:53
  • python爬虫爬取图片的简单代码

    2021-08-04 10:19:27
  • 讲解MySQL数据库的数据类型和建库策略

    2008-12-17 14:39:00
  • 一个拖动层和Onmouse自动下拉效果

    2007-10-08 21:25:00
  • Python cookbook(数据结构与算法)通过公共键对字典列表排序算法示例

    2021-07-23 01:24:36
  • Python中使用 Selenium 实现网页截图实例

    2022-07-04 06:28:16
  • python新手学习使用库

    2021-06-20 13:08:38
  • 像懒人一样去设计

    2009-04-23 12:43:00
  • python利用lxml库剩下操作svg图片

    2022-08-09 04:37:23
  • python防止随意修改类属性的实现方法

    2021-07-16 00:34:40
  • 十分钟轻松掌握dataframe数据选择

    2021-03-03 11:11:40
  • python将txt文件读入为np.array的方法

    2023-07-23 08:10:29
  • python windows安装cuda+cudnn+pytorch教程

    2023-02-04 04:35:02
  • 用Python爬取英雄联盟的皮肤详细示例

    2023-05-07 22:41:19
  • python如何提取英语pdf内容并翻译

    2023-06-13 13:37:27
  • python数据类型相关知识扩展

    2021-12-21 10:20:07
  • Python闭包与装饰器原理及实例解析

    2023-04-08 19:44:30
  • Python制作爬虫抓取美女图

    2021-05-15 12:47:45
  • 利用Python进行数据清洗的操作指南

    2022-07-22 22:59:41
  • Django实现jquery select2带搜索的下拉框

    2022-04-20 18:50:58
  • asp之家 网络编程 m.aspxhome.com