n = int(input())
f = [0] * (n + 1)
f[0] = 0
f[1] = 1
for i in range(2, n + 1):
f[i] = f[i - 1] + f[i - 2]
2分
登录后查看选项
10
关于 try‑except‑else‑finally 结构,以下说法正确的是?
2分
登录后查看选项
11
执行下面 Python 代码后,输出的结果是?
a = [1, 1]
for i in range(2, 10):
a.append(a[i - 1] + a[i - 2])
print(a[8])
2分
登录后查看选项
12
执行下面 Python 代码后,输出的结果是?
students = [("Alice", "B", 25), ("Bob", "A", 23), ("Cathy", "A", 22)]
sorted_students = sorted(students, key=lambda x: (x[1], x[2]))
print([s[0] for s in sorted_students])
2分
登录后查看选项
13
以下代码实现了根据交通灯颜色返回动作 (停、等、行) 的功能,以下哪个选项是正确的?
def traffic_action(color):
actions = {"红": "停", "黄": "等", "绿": "行"}
if color in actions:
return _____①_____
else:
return "无效颜色"
color = input("输入交通灯颜色: ")
action = traffic_action(color)
print(f"颜色 {color} 对应的动作是: {_____②_____}")
2分
登录后查看选项
14
文件 text.txt 的内容如下:
Python is a programming language. Python is easy to learn.
Many people use Python for data analysis and web development.
Python has a large community and many libraries.
以下代码实现了统计文件中单词 Python 出现的次数的功能,以下哪个选项是正确的?( )。
count = 0
with open("text.txt", "r") as f:
content = f._____①_____
words = content._____②_____
for word in words:
if word == "Python":
count += 1
print(f"Python出现次数:{count}")
n, m = map(int, input().split())
matrix = [list(map(int, input().split())) for _ in range(n)]
max_avg = float("-inf")
for i in range(_____①_____):
for j in range(_____②_____):
# 计算当前2×2子矩阵的和
total = matrix[i][j] + matrix[i][j + 1] + matrix[i + 1][j] + matrix[i + 1][j + 1]
avg = total / 4.0
if avg > max_avg:
max_avg = avg
print(f"{max_avg:.2f}")
2分
登录后查看选项
判断题 共10道
16
Python 程序执行 input () 函数时通常是使用键盘等输入设备来输入某个变量的值。
2分
登录后查看选项
17
执行下面 Python 代码后,输出结果为 [1, 2]。
a = [1, 2]
b = (a,)
a.append(3)
print(b[0])
2分
登录后查看选项
18
执行下面 Python 代码后,输出结果为 `[0,1,4] [0,1,4]`。
gen = (i ** 2 for i in range(3))
print(list(gen), list(gen))
2分
登录后查看选项
19
执行下面 Python 代码后,输出结果为 20。
num = 5
def test():
num = 10
global num
num = 20
test()
print(num)