主要内容 #
- if 语句的定义
- if 语句的使用
1. if 语句的定义 #
if的中文意思是:如果,要是,假如。
生活中有很多的“如果”,比如:
做人如果没有理想,跟咸鱼有什么分别
如果我有双翅膀,我就可以飞啦
程序中用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')
程序流程图如下:
3. 小结 #
if语句的定义和使用
OJ训练题 #
1、大于10的数 – ★
2、限行 – ★
3、判断相等 – ★
4、幸运圆盘 – ★★
5、环线地铁 – ★★★