with open('test.txt', 'w') as f:
f.write('Hello')
with open('test.txt', 'a') as f:
f.write('World')
with open('test.txt', 'r') as f:
print(f.read())
2分
登录后查看选项
11
在Python中,以下哪个选项可以正确地读取一个二进制文件并打印其内容?
2分
登录后查看选项
12
执行以下Python代码,如果文件 data.txt 不存在,输出结果是?
try:
with open('data.txt', 'r') as f:
content = f.read()
print("File read successfully.")
except FileNotFoundError:
print("File not found.")
except Exception as e:
print("An error occurred:", e)
2分
登录后查看选项
13
以下Python代码的时间复杂度是?
def func(n):
i = 0
while i * i * i < n:
i += 1
2分
登录后查看选项
14
下面程序空白处填上哪些内容可以实现程序的由小到大排序功能?
def selection_sort(arr):
n = len(arr)
for i in range(n-1):
min_index = i # 初始化最小索引
for j in range(i+1, n):
if arr[j] < arr[min_index]:
_______________ # 填写代码 ①
______________ # 填写代码 ②