#149. GESP Python 四级 2024年09月 客观题
GESP Python 四级 2024年09月 客观题
一、单选题(每题2分,共30分)
- 据有关资料,山东大学于1972年研制成功DJL-1计算机,并于1973年投入运行,其综合性能居当时全国第三位。DJL-1计算机运算控制部分所使用的磁心存储元件由磁心颗粒组成,设计存贮周期为2μs(微秒)。那么该磁心存储元件相当于现代计算机的( )。
{{ select(1) }}
内存磁盘CPU显示器
- IPv4版本的因特网总共有( )个A类地址网络。
{{ select(2) }}
65000200万126128
- 执行下面Python代码后,输出的结果是?( )
my_list = [1, 2, [3, 4]]
my_list[2].extend([5, 6])
print(my_list)
{{ select(3) }}
[1, 2, 5, 6][1, 2, [3, 4]][1, 2, [3, 4, 5, 6]][1, 2, [3, 4, [5, 6]]]
- 执行下面Python代码后,会发生什么?( )
my_tuple = (1, 2, (3, 4))
my_tuple[2] = (5, 6)
{{ select(4) }}
my_tuple变为(1, 2, (5, 6))代码正常执行,没有变化抛出ValueError异常抛出TypeError异常
- 执行下面Python代码后,输出的结果是?( )
try:
result = 10 / int('a')
except ValueError:
print("10", end="#")
else:
print("20", end="#")
finally:
print("30", end="#")
{{ select(5) }}
10#30#10#20#30#
- 执行下面Python代码后,输出的结果是?( )
def func(n):
return len([num for num in range(n) if num % 2 == 0])
print(func(20))
{{ select(6) }}
8101115
- 执行下面Python代码后,输出的结果是?( )
def func(*args):
return ''.join(args)
print(func('Hello', 'World'))
{{ select(7) }}
HelloWorldHello World"Hello" "World"抛出异常
- 执行下面Python代码后,输出的结果是?( )
def func(lst):
lst.append(10)
return lst
lstA = [1, 2, 3]
func(lstA)
print(lstA, func(lstA))
{{ select(8) }}
[1, 2, 3, 10, 10] [1, 2, 3, 10, 10][1, 2, 3] [1, 2, 3, 10][1, 2, 3, 10] [1, 2, 3, 10][1, 2, 3, 10] [1, 2, 3, 10, 10]
- 执行下面Python代码后,输出的结果是?( )
def tpADD(tpl):
tpl = tpl + (5, 6)
return tpl
tp = (1, 2, 3)
tpADD(tp)
print(tp, tpADD(tp))
{{ select(9) }}
(1, 2, 3, 5, 6, 5, 6) (1, 2, 3, 5, 6, 5, 6)(1, 2, 3, 5, 6) (1, 2, 3, 5, 6)(1, 2, 3) (1, 2, 3, 5, 6)(1, 2, 3) (1, 2, 3)
- 执行下面Python代码后,输出的结果是?( )
x = 5
def foo():
def bar():
global x
x = 10
bar()
print(x, end="#")
foo()
print(x, end="#")
{{ select(10) }}
5#5#10#5#5#10#10#10#
- 执行下面Python代码后,输出的结果是?( )
def func(d):
d['a'] = 5
c = {'a': 1, 'b': 2}
func(c)
print(c)
{{ select(11) }}
{'a': 1, 'b': 2}{'b': 2}{'a': 5, 'b': 2}抛出异常
- 以下Python代码实现的排序算法的时间复杂度是?( )
def func_sort(arr):
n = len(arr)
for i in range(n - 1):
min_idx = i
for j in range(i + 1, n):
if arr[j] < arr[min_idx]:
min_idx = j
arr[i], arr[min_idx] = arr[min_idx], arr[i]
{{ select(12) }}
- 执行下面Python代码后,输出的结果是?( )
tuples = [(1, 'apple'), (2, 'banana'), (0, 'cherry')]
sorted_tuples = sorted(tuples, key=lambda x: x[1])
print(sorted_tuples)
{{ select(13) }}
[(1, 'apple'), (0, 'cherry'), (2, 'banana')][(2, 'banana'), (1, 'apple'), (0, 'cherry')][(0, 'cherry'), (1, 'apple'), (2, 'banana')][(1, 'apple'), (2, 'banana'), (0, 'cherry')]
- 假设你正在爬楼梯,每次可以爬1阶或2阶。给定楼梯的阶数n,计算有多少种不同的方法可以爬到楼顶。以下Python代码的横线处应该填写?( )
def climbStairs(n):
if n == 1:
return 1
if n == 2:
return 2
# 初始化前两阶楼梯的数据
dp = [0] * (n + 1)
dp[1] = 1
dp[2] = 2
# 从第3阶楼梯开始,计算每一阶楼梯的爬法数量
for i in range(3, n + 1):
dp[i] =
return dp[n]
{{ select(14) }}
2 * dp[i - 1] + dp[i - 2]dp[i - 1] + dp[i - 2]2 * dp[i - 2]dp[i - 1] + 2 * dp[i - 2]
- 文件
numbers.txt的内容如下:
5
12
7
15
3
20
8
执行下面Python代码后,输出的结果是?( )
def func(file_path, threshold):
lst = []
with open(file_path) as file:
for line in file:
number = int(line.strip())
if number > threshold:
lst.append(number)
return lst
file_path = 'numbers.txt'
threshold = 12
selected_numbers = func(file_path, threshold)
print(selected_numbers)
{{ select(15) }}
[15, 20][12, 15, 20, 8][5, 12, 7, 15, 20, 8][12, 15, 20]
二、判断题(每题2分,共20分)
- 小杨最近开始学习C++编程,老师说C++是一门面向对象的编程语言,也是一门高级语言。( )
{{ select(16) }}
- 正确
- 错误
- 在Python程序中,自定义函数可以定义在主程序代码的前面,也可以定义在主程序代码的后面,都不会发生错误。( )
{{ select(17) }}
- 正确
- 错误
- 在Python程序中,如果自定义函数内没有return语句或者return语句不带任何返回值,那么该函数的返回值为False。( )
{{ select(18) }}
- 正确
- 错误
- try-except-else-finally异常处理结构中,只有try程序段中的语句没有异常,else程序段中的语句才会得到执行。( )
{{ select(19) }}
- 正确
- 错误
- Python中避免使用反斜线\指定文件路径时出错,如
C:\test\numbers.txt;常常使用正斜线/或者双反斜线\。( )
{{ select(20) }}
- 正确
- 错误
'w'可以作为open()函数的参数,表示以写的方式打开文件,若文件不存在,则会抛出异常。( )
{{ select(21) }}
- 正确
- 错误
- 下面这段程序的时间复杂度为线性阶。( )
def func(n):
i = 0
while i ** 2 < n:
i += 1
{{ select(22) }}
- 正确
- 错误
- 对一组数据
[5, 2, 6, 4, 8, 1, 7, 3]使用冒泡的方法按从大到小的顺序进行排序,则第2轮排序过后的结果是[6, 5, 8, 4, 7, 3, 2, 1]。( )
{{ select(23) }}
- 正确
- 错误
- 执行下面Python代码后,输出的结果为
(0, 0)。( )
lst = [(x, x**2) for x in range(-5, 6)]
a = min(lst, key=lambda x: abs(x[1]))
print(a)
{{ select(24) }}
- 正确
- 错误
- 在Python中表达式
{1, 3, 5} & {2, 4, 6} == {}的值为True。( )
{{ select(25) }}
- 正确
- 错误