主要内容 #
- if 语句的定义
- if 语句的使用
1. if 语句的定义 #
if的中文意思是:如果,要是,假如。 生活中有很多的“如果”,比如:
if语句的定义如下:
2. if 语句的使用 #
用程序实现以下逻辑: 如果考试考上了90分,成绩等级就是A
score = input('请输入成绩:')
score = float(score)
if score >= 90:
print('成绩等级为:A')
print('Thanks')
程序流程图如下:
用程序实现以下逻辑:
如果考试考上了90分,成绩等级就是A。如果考上了80分,成绩等级就是B
score = input('请输入成绩:')
score = float(score)
if score >= 90:
print('成绩等级为:A')
if score >= 80 and score < 90:
print('成绩等级为:B')
print('Thanks')
程序流程图如下: