2025年6月电子学会青少年软件编程(Python六级)等级考试试卷
客观题
六级
2025
2025-07-24 17:38:56
87次
一、单选题
执行以下代码后,file.txt 文件的内容是?( )
with open('file.txt', 'w') as f:
f.write('First line\n')
with open('file.txt', 'a') as f:
f.write('Second line\n')
with open('file.txt', 'r+') as f:
f.seek(0)
f.write('Replaced first line\n') | A. First line Second line |
B. Replaced first line Second line |
| C. First line Replaced first line |
D. Replaced first line |
【知识点】 电子学会Python六级
运行以下Python程序后,将打印输入两个整数的取余运算结果,划线处的代码为?( )
class Mi():
def __init__(self,a,b):
self.a=a
self.b=b
def yu(self):
return self.a % self.b
a=int(input('输入第一个数:'))
b=int(input('输入第二个数:'))
c=
print(c.yu()) | A. Mi(a%b) |
B. a%b |
| C. self.a % self.b |
D. Mi(a,b) |
【知识点】 电子学会Python六级
物流轨迹跟踪系统中若需获取前3条记录,以下哪种方式最高效?( )
conn = sqlite3.connect('logistics.db')
cursor = conn.cursor()
cursor.execute('''
SELECT track_id, location, timestamp
FROM tracking
WHERE package_id = ?
ORDER BY timestamp DESC''', ('PKG12345',))
# 获取最新轨迹
latest_record = cursor.fetchone() | A. [cursor.fetchone() for _ in range(3)] |
B. cursor.fetchmany(3) |
| C. cursor.fetchall()[:3] |
D. 循环调用fetchone()三次 |
【知识点】 电子学会Python六级
在处理日志文件时,需要把日志的行顺序反转,方便查看最新的日志记录(即文件里的内容按行倒序)。下面哪个代码能正确实现?( )
A.with open('old_file.txt', 'r') as f1, open('new_file.txt', 'w') as f2:
lines = f1.readlines()
lines.reverse()
f2.write(lines) |
B.with open('old_file.txt', 'r') as f1, open('new_file.txt', 'w') as f2:
lines = f1.read()
lines.reverse()
f2.write(lines) |
C.with open('old_file.txt', 'r') as f1, open('new_file.txt', 'w') as f2:
lines = f1.readlines()
for line in reversed(lines):
f2.write(line) |
D.with open('old_file.txt', 'r') as f1, open('new_file.txt', 'w') as f2:
lines = f1.read()
for line in reversed(lines):
f2.write(line) |
【知识点】 电子学会Python六级
仿照图形化软件中的映射,编写一段映射类。运行程序后,输入:5,映射后:1;输入:200,映射后:49。程序①处应补全的语句是?( )


class Ying():
def __init__(self,a,b,c,d,e):
self.a=a
self.b=b
self.c=c
self.d=d
self.e=e
def ys(self):
return (self.a*(self.e-self.d))/(self.c-self.b)
a=float(input('输入值:'))
b=Ying(a,0,1023,0,255)
print("映射前:%d 映射后:%d"%(a, ① )) | A. a.ys() |
B. b.ys() |
| C. b |
D. b.self() |
【知识点】 电子学会Python六级
在图书馆管理系统中,有一个列表 new_books = [('Book 1', 'Author 1'), ('Book 2', 'Author 2')],需要将这些书籍信息插入到 books 表中,以下代码正确的是?( )
A.import sqlite3
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.executemany('INSERT INTO books (title, author) VALUES (?, ?)', new_books)
conn.commit()
conn.close() |
B.import sqlite3
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO books (title, author) VALUES (?, ?)', new_books)
conn.commit()
conn.close() |
C.import sqlite3
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.executemany('INSERT INTO books (title, author) VALUES (?, ?)', new_books[0])
conn.commit()
conn.close() |
D.import sqlite3
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO books (title, author) VALUES (?, ?)', new_books[0])
conn.commit()
conn.close() |
【知识点】 电子学会Python六级
你有一个日志文件,需要不断将新的日志信息添加到文件末尾。以下哪种方式可以完成该功能?( )
A.with open('test.txt', 'w') as f:
f.write('new text') |
B.with open('test.txt', 'a') as f:
f.write('new text') |
C.with open('test.txt', 'r') as f:
f.write('new text') |
D.with open('test.txt', 'rb') as f:
f.write('new text') |
【知识点】 电子学会Python六级
