#146. GESP Python 四级 2025年06月 客观题

GESP Python 四级 2025年06月 客观题

一、单选题(每题2分,共30分)

  1. 2025年4月19日在北京举行了一场颇为瞩目的人形机器人半程马拉松赛。比赛期间,跑动着的机器人会利用身上安装的多个传感器所反馈的数据来调整姿态、保持平衡等,那么这类传感器类似于计算机的( )。

{{ select(1) }}

  • 处理器
  • 存储器
  • 输入设备
  • 输出设备
  1. 小杨购置的计算机使用一年后觉得内存不够用了,想购置一个容量更大的内存条,这时需要的内存条是( )。

{{ select(2) }}

  • RAM
  • ROM
  • CACHE
  • EPROM
  1. 执行下面Python代码后,输出的结果是?( )
s1 = {('a', 1), ('b', 2)}
s2 = {('b', 2), ('a', 1)}
t1 = (('a', 1), ('b', 2))
t2 = (('b', 2), ('a', 1))
print(s1 == s2, t1 == t2)

{{ select(3) }}

  • True False
  • False False
  • True True
  • False True
  1. 执行下面Python代码后,输出的结果是?( )
def func(*args):
    return sum(args) / len(args)
result = func(1, 2, 3, 4, 5)
print(result)

{{ select(4) }}

  • 15
  • 3
  • 3.0
  • 报错
  1. 以下哪个函数调用是合法的?( )
def func(a, b, *, c, d=0):
    pass

{{ select(5) }}

  • func(1, 2, 3, 4)
  • func(a=1, 2, c=3)
  • func(1, 2, 3, d=4)
  • func(1, 2, c=3)
  1. 执行下面Python代码后,输出的结果是?( )
x = 10
def func():
    x += 1
    return x
print(func())

{{ select(6) }}

  • 10
  • 11
  • 报错
  • None
  1. 执行下面Python代码后,输出的结果是?( )
func = lambda x: x * 2 if x > 0 else x // 2
print(func(-4), func(4))

{{ select(7) }}

  • 2 -8
  • -2 8
  • -8 2
  • 报错
  1. 执行下面Python代码后,输出的结果是?( )
def apply(func, x):
    return func(x)
def square(n):
    return n * n
result = apply(square, 4)
print(result)

{{ select(8) }}

  • 16
  • 8
  • 4
  • 报错
  1. 执行下面Python代码后,会发生什么?( )
try:
    raise ValueError
except Exception:
    print("A")
except ValueError:
    print("B")

{{ select(9) }}

  • 打印"A"
  • 打印"B"
  • 同时打印"A"和"B"
  • 报错
  1. 执行下面Python代码后,输出的结果是?( )
try:
    1 / 0
except ValueError:
    print("A")
else:
    print("B")
print("C")

{{ select(10) }}

  • A C
  • B C
  • C
  • 报错
  1. 以下哪个选项可以正确读取文件"data.txt"的全部内容并返回一个字符串?
with open("data.txt", "r") as f:
    content = 

{{ select(11) }}

  • f.readlines()
  • f.readline()
  • f.read()
  • f.read(100)
  1. 以下哪种文件打开模式可以在不截断文件的情况下同时支持读写?( )

{{ select(12) }}

  • "w"
  • "r+"
  • "a"
  • "x"
  1. 以下哪种排序算法的时间复杂度在最坏情况下是(O(n^2))?( )

{{ select(13) }}

  • 冒泡排序
  • 选择排序
  • 插入排序
  • 以上都是
  1. 执行以下代码后,输出的结果是?( )
data = ['apple', 'Banana', 'cherry']
print(sorted(data))

{{ select(14) }}

  • ['apple', 'Banana', 'cherry']
  • ['Banana', 'apple', 'cherry']
  • ['apple', 'cherry', 'Banana']
  • ['cherry', 'Banana', 'apple']
  1. 给定一个整数数组nums,计算其最长递增子序列的长度。子序列可以不连续,但必须保持原数组的顺序。例如:nums = [10, 9, 2, 5, 3, 7, 101, 18]的最长递增子序列是[2, 3, 7, 101],长度为4。
def length_of_LIS(nums):
    dp = [1] * len(nums)  # dp[i] 表示以 nums[i] 结尾的最长递增子序列长度
    for i in range(1, len(nums)):
        for j in range(i):
            if nums[j] < nums[i]:
                dp[i] =  # 填空
    return max(dp)

{{ select(15) }}

  • dp[j] + 1
  • dp[i] + 1
  • min(dp[i], dp[j] + 1)
  • max(dp[i], dp[j] + 1)

二、判断题(每题2分,共20分)

  1. 现在,人们参加各种闭卷考试时通常都不允许将智能手机、平板电脑等带入考场,因为智能手表通常都有嵌入操作系统及通信等功能,所以也不允许携带入考场。( )

{{ select(16) }}

  • 正确
  • 错误
  1. 执行下面Python代码后,输出的结果为3。( )
data = {'ids': [1, 2], 'name': 'test'}
data['ids'].extend(['g', 'e', 's', 'p'])
print(len(data['ids']))

{{ select(17) }}

  • 正确
  • 错误
  1. 执行下面Python代码会报错,因为lambda函数不能有默认参数。( )
f = lambda x, y=2: x + y
f(1)

{{ select(18) }}

  • 正确
  • 错误
  1. 执行下面Python代码后,输出的结果为[1, 4, 9]。( )
print(list(map(lambda x: x**2, [1, 2, 3])))

{{ select(19) }}

  • 正确
  • 错误
  1. 执行下面Python代码后,将只输出try。( )
def test():
    try:
        return "try"
    finally:
        print("finally执行了")
print(test())

{{ select(20) }}

  • 正确
  • 错误
  1. 在Python中,readlines()方法返回的文件内容包含每行末尾的换行符(\n)。( )

{{ select(21) }}

  • 正确
  • 错误
  1. 递推算法的核心思想是利用已知条件逐步推导后续结果。( )

{{ select(22) }}

  • 正确
  • 错误
  1. 选择排序是一种稳定的排序算法。( )

{{ select(23) }}

  • 正确
  • 错误
  1. 以下代码的时间复杂度是(O(n))。( )
def func(n):
    for i in range(n):
        for j in range(n):
            print(i, j)

{{ select(24) }}

  • 正确
  • 错误
  1. 以下代码的空间复杂度是(O(1))。( )
def sum_elements(arr):
    total = 0
    for num in arr:
        total += num
    return total

{{ select(25) }}

  • 正确
  • 错误