万卷网> 电子学会考级 >Python等级考试 > 2025年6月电子学会青少年软件编程(Python六级)等级考试试卷

2025年6月电子学会青少年软件编程(Python六级)等级考试试卷
客观题 六级 2025 2025-07-24 17:38:56 87

一、单选题

1.

在tkinter中,用于创建按钮的类是?( )

A.

Button

B.

Label

C.

Entry

D.

Frame

2.

执行以下代码后,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

3.

在Python中,使用json模块将Python字典转换为JSON字符串的方法是?( )

A.

json.load()

B.

json.loads()

C.

json.dump()

D.

json.dumps()

4.

Python语言关于类的说法错误的是?( )

A.

函数可以定义到类中,称为方法。功能不变,使用格式不同

B.

定义类后,必须定义一个类的实例才能使用类的方法

C.

导入类必须重命名后才能使用,如:import turtle as t

D.

可以导入单个类,也可以导入多个类。 如:导入单个:from car import Car 导入多个: from module_name import Class_a, Class_b

5.

运行以下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)

6.

物流轨迹跟踪系统中若需获取前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()三次

7.

你有一个大文件,需要从文件的第 10 个字节处开始读取数据。应该使用以下哪个方法?( )

A.

f.seek(10)

B.

f.tell(10)

C.

f.read(10)

D.

f.write(10)

8.

从json文件中读取数据,并使用json模块中的load方法将其转换为Python的字典对象。下面哪个选项是正确的代码?( )

A.

d = json.load(open('data.json'))

B.

d = json.loads('data.json')

C.

d = open('data.json').load(json)

D.

d = open('data.json').loads(json)

9.

在处理日志文件时,需要把日志的行顺序反转,方便查看最新的日志记录(即文件里的内容按行倒序)。下面哪个代码能正确实现?( )

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)
10.

在Python中,以下代码的输出是? ( )

import numpy as np
x = np.arange(10, 20, 3)
print(x[-1])
A.

10

B.

16

C.

19

D.

报错

11.

在tkinter中要使Button点击时执行函数show(),正确写法是?( )

A.

tk.Button(root, command=show()).pack()

B.

tk.Button(root, command=show).pack()

C.

tk.Button(root, bind=show).pack()

D.

tk.Button(root, onclick=show).pack()

12.

用matplotlib画图时,显示折线图常用的函数是?( )

A.

plt.show()

B.

plt.plot()

C.

plt.scatter()

D.

plt.hist()

13.

Python语言关于类的定义错误的是?( )

A.

类名的每个单词的首字母都要大写,且不使用下划线分隔单词

B.

类命名尽量简洁且有意义

C.

类的定义必须在引用之前

D.
class Student_Info():
           def __init__(l,w,h):
               self.l=l
               self.w=w
               self.h=h
14.

下列代码运行后,图表的标题会显示什么?( )

import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = "SimHei"
plt.plot([1, 2, 3], [4, 5, 6])
plt.title("成绩走势")
plt.show()
A.

不显示标题

B.

"成绩走势"

C.

"matplotlib图"

D.

程序出错

15.

在tkinter中执行以下代码后,窗口将显示什么?( )

import tkinter as tk
root = tk.Tk()
tk.Label(root, text="Hello").pack(side="left")
tk.Label(root, text="World").pack()
root.mainloop()
A.

Hello在左,World在右

B.

Hello在上,World在下

C.

Hello在左,World自上居中

D.

Hello在左,World在下方

16.

用Python语言对SQLite数据库进行编程,实现打开和关闭stu.db数据库文件。下列命令语句,执行先后顺序正确选项是?( )

①conn = sqlite3.connect("test.db")

②cur = conn.cursor( )

③import sqlite3 

④conn.close( ) 

⑤cur.close( ) 

A.

①②③④⑤

B.

②①③⑤④

C.

③①②⑤④

D.

③①②④⑤

17.

仿照图形化软件中的映射,编写一段映射类。运行程序后,输入: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()

18.

在图书馆管理系统中,有一个列表 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()
19.

在tkinter中用于处理按钮点击事件的参数是?( )

A.

action

B.

click

C.

command

D.

event

20.

你有一个日志文件,需要不断将新的日志信息添加到文件末尾。以下哪种方式可以完成该功能?( )

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')
21.

某小型书店需要管理其图书库存,决定使用SQLite数据库来存储图书信息。在创建数据库和图书表的过程中,以下哪个步骤是正确的?( )

A.

使用connect('library.db')创建数据库连接后,直接执行INSERT语句插入数据

B.

创建表后,必须使用commit()方法提交事务,否则数据不会保存

C.

关闭数据库连接时,先关闭游标,再关闭连接

D.

使用CREATE TABLE语句时,必须指定主键

22.

在Python中,关于一维数据的CSV文件存储,以下说法正确的是?( )

A.

CSV文件只能存储数值型数据

B.

写入CSV时,一维列表应转换为二维嵌套列表

C.

csv.writerow()方法可以直接写入一维列表

D.

读取CSV文件时,必须指定delimiter=';'

23.

如果你要用numpy快速创建一个10个元素、值全为0的一维数组,不正确的方法是?( )

A.

numpy.zeros(10)

B.

numpy.zeros([10])

C.

numpy.zeros((10,))

D.

numpy.zeros([10.])

24.

在Python中,以下代码的功能是?( )

with open('data.csv', 'r') as f:
        reader = csv.DictReader(f)
        for row in reader:
                print(row['name'])
A.

以字典形式读取CSV,打印name列

B.

将CSV转为JSON格式输出

C.

统计name列的出现次数

D.

修改CSV文件的name列

25.

使用numpy时,以下哪种操作可以用来计算数组的平均值?( )

A.

numpy.sum()

B.

numpy.mean()

C.

numpy.max()

D.

numpy.size()

二、判断题

1.

在Python语言中,先定义类,再使用类创建出具体的对象:即实例。不同的实例可以带不同的参数,但它们使用相同的方法。( )

A.正确 B.错误
2.

Python 中的 with 语句在处理文件操作时,会自动关闭文件,即使在执行过程中发生异常也能保证文件被正确关闭。( )

A.正确 B.错误
3.

在Python语言中,针对同一个对象(实例)的相同操作,可以定义类和类的方法,以便重复调用。( )

A.正确 B.错误
4.

一个学生成绩管理系统需要从SQLite数据库中查询学生信息。在执行查询操作时,fetchmany(size=2)会返回结果中的前两行。( )

A.正确 B.错误
5.

tkinter中主窗口必须手动设置geometry()才能显示。( )

A.正确 B.错误
6.

numpy数组比Python普通列表占用内存更高,速度更慢。( )

A.正确 B.错误
7.

在Python中,json.loads()可以将JSON字符串转为Python字典。( )

A.正确 B.错误
8.

在Python中,使用json.load()读取JSON文件时,文件对象必须以二进制模式打开(如'rb')。( )

A.正确 B.错误
9.

numpy只能处理一维数据,不能处理多维矩阵。( )

A.正确 B.错误
10.

在 Python 中,使用open()函数打开文件进行读取时,文件路径必须是绝对路径。( )

A.正确 B.错误
公众号
客服 反馈
顶部