#GESPP4202406. GESP-2024年06月份 Python 四级 客观题
GESP-2024年06月份 Python 四级 客观题
一. 单选题(每题 2 分,共 30 分)
- ⼩杨⽗母带他到某培训机构给他报名参加CCF组织的GESP认证考试的第1级,那他可以选择的认证语⾔有⼏种?( )
{{ select(1) }}
- 1
- 2
- 3
- 4
- 下⾯流程图在yr输⼊2024时,可以判定yr代表闰年,并输出2月是29天 ,则图中菱形框中应该填⼊( )。
{{ select(2) }}
- (yr%4000) || (yr%40)
- (yr%4000) || (yr%40 && yr%100!=0)
- (yr%4000) && (yr%40)
- (yr%4000) && (yr%40 && yr%100!=0)
3.执⾏下⾯Python代码后,输出的结果可能是?( )
name = ('Tom', 'Join', 'Gaia')
age = (10, 13, 12)
print({(a.upper(), b) for a, b in zip(name, age)})
{{ select(3) }}
- {'Tom': 10, 'Join': 13, 'Gaia': 12}
- {'TOM': 10, 'JOIN': 13, 'GAIA': 12}
- {('JOIN', 13), ('TOM', 10), ('GAIA', 12)}
- {('Join', 13), ('Tom', 10), ('Gaia', 12)}
4.函数fun的定义如下,调⽤该函数的语句错误的是?( )
def fun(x, y, z=3):
print(x, y, z)
{{ select(4) }}
- fun(1, 2, 3)
- fun(1, 2)
- fun(y=2, x=1)
- fun(1, y=2, 3)
- 执⾏下⾯Python代码后,输出的结果是?( )
def fun(x, y, *nums):
res = x + y
for i in nums:
res += i
return res
print(fun(10, 20, 15, 25, 30))
{{ select(5) }}
- 30
- 45
- 100
- 语法错误
- 执⾏下⾯Python代码后,输出的结果是?( )
def fun(x, y, **kwargs):
res = x + y
for i in kwargs.values():
res += i
return res
print(fun(10, 20, A=6, B=1, C=3))
{{ select(6) }}
- 40
- 36
- 30
- 语法错误
- 执⾏下⾯python代码后,输出的结果是?( )
def add():
count = 1
def fun():
nonlocal count
print(count, end="#")
count += 2
return fun
a = add()
a()
a()
{{ select(7) }}
- 1#3#
- 1#1#
- 3#3#
- add函数语法错误
- 执⾏下⾯python代码后,输出的结果是?( )
s = 1
def sums(n):
global s
s = 0
s = s + n
print(s, end="#")
sums(5)
print(s, end="#")
{{ select(8) }}
- 5#5#
- 5#1#
- 1#1#
- 1#5#
- 执⾏下⾯python代码后,输出的结果是?( )
def add(c):
d = c.append(40)
return d
a = [10, 20, 30]
b = add(a)
print(a, b)
{{ select(9) }}
- [10, 20, 30] [10, 20, 30]
- [10, 20, 30, 40] [10, 20, 30, 40]
- [10, 20, 30] [10, 20, 30, 40]
- [10, 20, 30, 40] None
10.在⼀个农场上,有⼀头母⽜。根据农场的规则,这头母⽜每年年初都会⽣出⼀头⼩母⽜。每头新⽣的⼩母⽜从它们出⽣的第四个年头开始,也会每年年初⽣出⼀头新的⼩母⽜。假设没有母⽜死亡,并且每头母⽜都严格遵循这个规则。下列程序⽤来计算在第 n(n<30)年时,农场上共有多少头母⽜,其中横线处填写的代码为?()
lst = [0] * 100
lst[1:4] = [1, 2, 3, 4]
def calculate_cows(n):
if n <= 4:
return lst[n]
i = 5
while i <= n:
lst[i] = __________
i += 1
return lst[i - 1]
{{ select(10) }}
- lst[i - 1] + lst[i - 3]
- lst[i - 2] + lst[i - 3]
- lst[i - 1] + lst[i - 2]
- lst[-1] + lst[-3]
- 程序段如下:
def fun(arr: list):
n = len(arr)
for i in range(n - 1):
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
{{ select(11) }}
12.执⾏下⾯Python代码后,输出的结果是?( )
users = [
{"name": "Tom", "skills": {"Python", "Java", "C++"}},
{"name": "Join", "skills": {"Python", "Java"}},
{"name": "Gaia", "skills": {"Java", "C++", "SQL"}}
]
skills_sets = (user['skills'] for user in users)
common_skills = set.intersection(*skills_sets)
print(common_skills)
{{ select(12) }}
- {'Java', Python'}
- {SQL', 'C++'}
- {'Java', 'SQL', 'Python', 'C++'}
- {'Java'}
- 执⾏下⾯Python代码后,输出的结果是?( )
lst = [1, 4, 3, 5, 2]
lst = [i[0] for i in sorted(enumerate(lst), key=lambda x: x[1])]
print(lst)
{{ select(13) }}
- [3, 1, 2, 4, 0]
- [0, 4, 2, 1, 3]
- [3, 0, 2, 1, 4]
- [0, 3, 2, 4, 1]
- 执⾏下⾯Python代码后,⽂件ip.txt中的内容⽤记事本打开时显⽰为?( )
with open("ip.txt", "w") as f:
lst = ["202.206.224.21\n", "192.168.224.1\n"]
f.writelines(lst)
{{ select(14) }}
- 202.206.224.21192.168.224.1
- 202.206.224.21 192.168.224.1
- 202.206.224.21\n192.168.224.1
- 202.206.224.21\n192.168.224.1\n
15 执⾏下⾯Python代码,输⼊0和字符串“abc”后,输出的结果是?( )
try:
a = int(input())
b = int(input())
x = a / b
print(x, end="#")
except ZeroDivisionError:
print(0, end="#")
except:
print(1, end="#")
else:
print(2, end="#")
finally:
print(3, end="#")
{{ select(15) }}
- 0#2#3#
- 0#3#
- 1#2#3#
- 1#3#
二. 判断题(每题 2 分,共 20 分)
- GESP测试是对认证者的编程能⼒进⾏等级认证,同⼀级别的能⼒基本上与编程语⾔⽆关。( ) {{ select(16) }}
- 对
- 错
- 在Python中,print(list("GESP"))执⾏后输出['G', 'E', 'S', 'P']。( ) {{ select(17) }}
- 对
- 错
- 执⾏下⾯Python代码后,输出两个True。
print("h" in "hello")
print("he" in "hello")
{{ select(18) }}
- 对
- 错
- 执⾏下⾯Python代码后,输出两个True。
lst1 = [1, 2, 3]
lst2 = lst1[:]
print(lst1 == lst2, lst1 is lst2)
{{ select(19) }}
- 对
- 错
- 执⾏下⾯Python代码,调⽤函数fun可以得到⼀个元组类型的数据。
def fun(a, b):
return a // b, a % b
print(type(fun(8, 5)))
{{ select(20) }}
- 对
- 错
- Python程序中,全局变量与局部变量不允许重名 {{ select(21) }}
- 对
- 错
- 下⾯这段程序的时间复杂度为平⽅阶 。( )
def fun(n):
sum1 = 0
for i in range(n):
sum1 += i
{{ select(22) }}
- 对
- 错
- Python在处理程序异常时,异常处理结构能够发现程序段中的语法错误( )
{{ select(23) }}
- 对
- 错
- 要打开⼀个已经存在的图⽚⽂件并读取但不修改数据,则打开模式应该设定为rb( ) {{ select(24) }}
- 对
- 错
- 执⾏下⾯Python代码后,输出的结果为za( )
print(max('az', 'za', key=lambda a: a[0]))
{{ select(25) }}
- 对
- 错