14.作业

一、判断题(共10小题,10分)
题型得分 10
文件对象的seek()方法用来返回文件位置指示器(文件指针)的当前位置。(1分)
A. 对
B. 错
我的答案:
B
题目得分 1
参考答案:
B
好的习惯,文件使用完毕后必须显式关闭文件。(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
CSV文件是纯文本文件。(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
为了防止文件中已存在的数据被意外清除,在打开文件前可以检测该文件是否存在。使用os.path模块中的isdir方法判断一个文件是否存在。(1分)
A. 对
B. 错
我的答案:
B
题目得分 1
参考答案:
B
以写模式打开的文件无法进行读操作。(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
Python第三方扩展库openpyxl支持Excel文件的读写操作。

(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
打开文件的含义是指将文件对象与外存上的文件建立联系。成功打开文件后,对该文件的操作都将通过文件对象来完成。

(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
文件默认以二进制文件模式打开。打开文本文件要显式指定文本文件模式。

(1分)
A. 对
B. 错
我的答案:
B
题目得分 1
参考答案:
B
序列化指的是从字节流中提取出对象的过程。(1分)
A. 对
B. 错
我的答案:
B
题目得分 1
参考答案:
B
内存文件不是存放在外存上的真正文件,而是存放在内存中的虚拟文件。(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
二、填空题(共15小题,30分)
题型得分 26
下面程序的输出结果为________ (注意:不要有任何多余的空格)。

def main():
outfile = open(“temp.txt”, “w”)
outfile.write(“Hello\n”)
outfile.write(“Aloha\n”)
outfile.close()
infile = open(“temp.txt”, “r”)
text = “”
for line in infile:
text += line.rstrip()
infile.close()
print(text)

main()

(2分)
我的答案:
HelloAloha
题目得分 2
参考答案:
HelloAloha
下面程序执行后,文件temp.txt中内容是________。

def main():
fun(“temp.txt”, “amazing”)
fun(“temp.txt”, “awesome”)

def fun(filename,s):
outfile = open(filename, “w”)
outfile.write(s)
outfile.close()

main()
【来源】
《Python程序设计基础》第10章思考与练习。

(2分)
我的答案:
amazingawesome
题目得分 0
参考答案:
awesome
下面程序的输出结果为________ 。

def main():
iofile = open(“temp.txt”, “w+”)
for i in range(1, 10):
iofile.write(str(i))
iofile.seek(7)
print(iofile.read(1))
iofile.close()

main()
【来源】
《Python程序设计基础》第10章思考与练习。

(2分)
我的答案:
8
题目得分 2
参考答案:
8
下面程序的输出结果为________ 。

def main():
x = 20
y = 30
outfile = open(“temp.txt”, “w”)
outfile.write(str(x) + " " +str(y))
outfile.close()
infile = open(“temp.txt”,“r”)
s = infile.read()
numbers = [eval(value) for value in s.split()]
for number in numbers:
print(number, end=’#’)
infile.close()

main()

(2分)
我的答案:
20#30#
题目得分 2
参考答案:
20#30#
下面程序的输出结果为________ (注意:不要有任何多余的空格)。

def main():
lst = [“Hello”, “Aloha\n”]
outfile = open(“temp.txt”, “w”)
outfile.writelines(lst)
outfile.close()
infile = open(“temp.txt”, “r”)
text = infile.read().rstrip()
infile.close()
print(text)

main()

(2分)
我的答案:
HelloAloha
题目得分 2
参考答案:
HelloAloha
对文件进行写入操作之后,(注:填写英文)方法用来在不关闭文件对象的情况下强制将缓冲区内容写入文件。(2分)
我的答案:
flush
题目得分 2
参考答案:
flush()、flush
下面程序的输出结果为
(注意:不要有任何多余的空格)。
f = open(“temp.txt”, “w”)
f.write(“Lux et Veritas”)
f.close
f = open(“temp.txt”, “rb”)
f.read(3)
f.seek(4,1)
print(f.tell())
(2分)
我的答案:
7
题目得分 2
参考答案:
7
解决数据永久性保存的有效方式是使用________(注:填写中文)。

(2分)
我的答案:
题目得分 0
参考答案:
文件
文件使用完毕后必须关闭文件。(注:填写英文)方法用来显式关闭文件。(2分)
我的答案:
close
题目得分 2
参考答案:
close()、close
Python内置函数
(注:填写英文)用来打开或创建文件并返回文件对象。(2分)
我的答案:
open
题目得分 2
参考答案:
open()、open
使用上下文管理________(注:填写英文单词)语句可以自动管理文件对象,不论何种原因,都能保证文件被正确关闭。(2分)
我的答案:
with
题目得分 2
参考答案:
with
若有以下程序:
1 f = open(“temp.txt”,“w+”)
2 f.write(“Lux et Veritas”)
3 f.seek(4,1)
程序中存在的错误在第________行(注:填写阿拉伯数字)。(2分)
我的答案:
3
题目得分 2
参考答案:
3
Python提供了一个专门处理CSV文件的________(注:填写英文)模块。

(2分)
我的答案:
csv
题目得分 2
参考答案:
csv
通常有两种类型的文件:文本文件和________(注:填写中文)。(2分)
我的答案:
二进制文件
题目得分 2
参考答案:
二进制文件
下面程序的输出结果为________ (注意:不要有任何多余的空格)。
f = open(“temp.txt”,“w+”)
f.write(“Lux et Veritas”)
f.seek(7)
s = f.read(3)
f.close()
print(s)
(2分)
我的答案:
Ver
题目得分 2
参考答案:
Ver
三、单项选择题(共20小题,40分)
题型得分 40
打开文件C:\scores.txt进行读操作,使用( )。

(2分)
A. infile = open(“C:\scores.txt”, “r”)
B. infile = open(“C:\scores.txt”, “r”)
C. infile = open(file = “C:\scores.txt”, “r”)
D. infile = open(file = “C:\scores.txt”, “r”)
我的答案:
B
题目得分 2
参考答案:
B
打开文件C:\scores.txt进行写操作,使用( )。

(2分)
A. outfile = open(“C:\scores.txt”, “w”)
B. outfile = open(“C:\scores.txt”, “w”)
C. outfile = open(file = “C:\scores.txt”, “w”)
D. outfile = open(file = “C:\scores.txt”, “w”)
我的答案:
B
题目得分 2
参考答案:
B
从infile文件对象读取2个字符,使用( )。

(2分)
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
我的答案:
A
题目得分 2
参考答案:
A
打开文件C:\scores.txt追加数据,使用( )。

(2分)
A. outfile = open(“C:\scores.txt”, “a”)
B. outfile = open(“C:\scores.txt”, “rw”)
C. outfile = open(file = “C:\scores.txt”, “w”)
D. outfile = open(file = “C:\scores.txt”, “w”)
我的答案:
A
题目得分 2
参考答案:
A
下列( )说法是错误的。

(2分)
A. 当打开一个文件进行写操作,如果文件不存在,创建一个新文件
B. 当打开一个文件进行写操作,如果文件已经存在,这个存在的文件被新文件覆盖
C. 当打开一个文件进行写操作,如果文件已经存在,出现一个错误
我的答案:
C
题目得分 2
参考答案:
C
下列( )说法是正确的。

(2分)
A. 当打开一个文件进行读操作,如果文件不存在,出现一个错误
B. 当打开一个文件进行写操作,如果文件不存在,出现一个错误
C. 当打开一个文件进行读操作,如果文件不存在,程序将打开一个空文件
我的答案:
A
题目得分 2
参考答案:
A
从infile文件对象读取文件的所有数据并作为一个字符串返回,使用( )。

(2分)
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
我的答案:
B
题目得分 2
参考答案:
B
writelines()方法将( )写入文件。

(2分)
A. 一个字符串
B. 一个字符串列表
C. 一个浮点数列表
D. 一个整数列表
我的答案:
B
题目得分 2
参考答案:
B
write()方法将( )写入文件。

(2分)
A. 一个字符串
B. 一个布尔值
C. 一个浮点数
D. 一个整数
我的答案:
A
题目得分 2
参考答案:
A
打开文件c:\scores.dat进行二进制写操作,使用( )。

(2分)
A. outfile = open(“c:\scores.dat”, “wb”)
B. outfile = open(“c:\scores.dat”, “w”)
C. outfile = open(“c:\scores.dat”, “a”)
D. outfile = open(“c:\scores.dat”, “w”)
我的答案:
A
题目得分 2
参考答案:
A
从infile文件对象读取文件的一行数据并作为一个字符串返回,使用( )。

(2分)
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
我的答案:
C
题目得分 2
参考答案:
C
从infile文件对象读取文件的所有行数据,使用( )。

(2分)
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
我的答案:
D
题目得分 2
参考答案:
D
readlines()方法返回( )。

(2分)
A. 一个字符串
B. 一个字符串(行)列表
C. 一个浮点数列表
D. 一个整数列表
我的答案:
B
题目得分 2
参考答案:
B
( )函数可以用来检查文件f是否存在。

(2分)
A. os.path.isFile(f)
B. os.path.exists(f)
C. os.path.isfile(f)
D. os.isFile(f)
我的答案:
C
题目得分 2
参考答案:
C
打开文件c:\scores.dat进行二进制读操作,使用( )。

(2分)
A. infile = open(“c:\scores.dat”, “rb”)
B. infile = open(“c:\scores.dat”, “r”)
C. infile = open(“c:\scores.dat”, “wrb”)
D. infile =open(“c:\scores.dat”, “r”)
我的答案:
A
题目得分 2
参考答案:
A
打开文件c:\scores.txt进行读写操作,使用( )。

(2分)
A. iofile = open(“c:\scores.txt”,“r”)
B. iofile = open(“c:\scores.txt”, “w”)
C. iofile = open(“c:\scores.txt”, “ab”)
D. iofile = open(“c:\scores.txt”, “r+”)
我的答案:
D
题目得分 2
参考答案:
D
可以使用( )方法进行二进制读操作。

(2分)
A. read
B. input
C. load
D. receive
我的答案:
C
题目得分 2
参考答案:
C
调用( )方法将字符串转换成原始字节数据。
(2分)
A. encode()
B. decode()
C. convert()
D. toString()
我的答案:
A
题目得分 2
参考答案:
A
可以使用( )方法进行二进制写操作。

(2分)
A. write
B. output
C. dump
D. send
我的答案:
C
题目得分 2
参考答案:
C
调用( )方法将原始字节数据转换成字符串。(2分)
A. encode()
B. decode()
C. convert()
D. toString()
我的答案:
B
题目得分 2
参考答案:
B

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
我很抱歉,作为一个语言模型AI,我无法直接查询数据库。但是,我可以告诉您如何实现这些查询。 12. 查询数据库中共有多少个班级。 您可以使用以下SQL语句查询: ```sql SELECT COUNT(DISTINCT class) FROM your_table; ``` 其中,`your_table`是您的数据表名,`class`是班级对应的列名。 13. 查询选修三门以上(含三门)课程的学生的学号和作业1平均分、作业2平均分和作业3平均分。 您可以使用以下SQL语句查询: ```sql SELECT student_id, AVG(score1) AS avg_score1, AVG(score2) AS avg_score2, AVG(score3) AS avg_score3 FROM your_table WHERE course_count >= 3 GROUP BY student_id; ``` 其中,`your_table`是您的数据表名,`student_id`是学生ID对应的列名,`score1`、`score2`、`score3`是作业1、作业2、作业3对应的列名,`course_count`是学生选修课程数对应的列名。 14. 查询于兰兰的选课信息,列出学号、姓名、课程名(使用两种连接查询的方式)。 您可以使用以下两种连接查询方式: 方式一:使用INNER JOIN ```sql SELECT s.student_id, s.student_name, c.course_name FROM student_table s INNER JOIN course_table c ON s.student_id = c.student_id WHERE s.student_name = '于兰兰'; ``` 其中,`student_table`是学生表名,`course_table`是选课表名,`student_id`是学生ID对应的列名,`student_name`是学生姓名对应的列名,`course_name`是课程名称对应的列名。 方式二:使用SUBQUERY ```sql SELECT student_id, student_name, course_name FROM student_table WHERE student_id IN ( SELECT student_id FROM course_table WHERE student_name = '于兰兰' ); ``` 其中,`student_table`是学生表名,`course_table`是选课表名,`student_id`是学生ID对应的列名,`student_name`是学生姓名对应的列名,`course_name`是课程名称对应的列名。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值