- Python程序设计与算法基础教程(第2版)(微课版)
- 江红 余青松
- 897字
- 2025-02-25 21:55:20
3.4 复习题
一、选择题
1. 下面的Python循环体的执行次数与其他不同的是________。

2. 执行下列Python语句将产生的结果是________。

A. Equal
B. Not Equal
C. 编译错误
D. 运行时错误
3. 执行下列Python语句将产生的结果是________。

A. 输出1
B. 输出True
C. 输出False
D. 编译错误
4. 用if语句表示如下分段函数f(x),下面程序不正确的是________。

5. 下面的if语句统计满足“性别(gender)为男、职称(rank)为教授、年龄(age)小于40岁”条件的人数,正确的语句为________。
A. if(gender=="男"or age <40 and rank=="教授"):n+=1
B. if(gender=="男"and age <40 and rank=="教授"):n+=1
C. if(gender=="男"and age <40 or rank=="教授"):n+=1
D. if(gender=="男"or age <40 or rank=="教授"):n+=1
6. 下面的程序段求x和y两个数中的大数,________是不正确的。

7. 下面的if语句统计“成绩(score)优秀的男生以及不及格的男生”的人数,正确的语句为________。
A. if(gender=="男"and score <60 or score >=90):n+=1
B. if(gender=="男"and score <60 and score >=90):n+=1
C. if(gender=="男"and(score <60 or score >=90)):n+=1
D. if(gender=="男"or score <60 or score >=90):n+=1
8. 用if语句表示如下分段函数:

下面程序段不正确的是________。

9. 在以下for语句结构中,_______不能完成1~10的累加功能。
A. for i in range(10,0):total+=i
B. for i in range(1,11):total+=i
C. for i in range(10,0,-1):total+=i
D. for i in(10,9,8,7,6,5,4,3,2,1):total+=i
二、填空题
1. 迭代器是一个对象,表示可迭代的数据集合,包括方法________和________,可实现迭代功能。
2. 在Python无穷循环while True:的循环体中可以使用________语句退出循环。
3. Python语句“for i in range(1,21,5):print(i,end='')”的输出结果为________。
4. Python语句“for i in range(10,1,-2):print(i,end='')”的输出结果为________。
5. 循环语句for i in range(-3,21,4)的循环次数为________。
6. 要使语句for i in range(__,-4,-2)循环执行15次,则循环变量i的初值应当为________。
7. 执行下列Python语句后的输出结果是________,循环执行了________次。

三、思考题
1. 说明以下3个if语句的区别:

2. 下列Python语句的运行结果为________。

3. 阅读下面的Python程序,请问程序的功能是什么?

4. 阅读下面的Python程序,请问输出结果是什么?

5. 阅读下面的Python程序,请问输出结果是什么?程序的功能是什么?

6. 阅读下面的Python程序,请问输出结果是什么?程序的功能是什么?

7. 阅读下面的Python程序,请问输出结果是什么?程序的功能是什么?
