2024年3月电子学会青少年软件编程(Python六级)等级考试试卷
剩余时间 --:--:--
单选题 共 25 题
1.

下面代码的输出结果正确的是?()

import json
data={
    "name":"Alice",
    "age":25,
    "city":"New York"
}
text=json.dumps(data)
print(text)
2.

以下代码实现将鼠标移到按钮上时按钮变红,鼠标移开时按钮变蓝,划线处的代码是?()

from tkinter import*
root=Tk()
root.title()
root.geometry('450x350')
btn1=Button(root,text='1')
btn1.place(x=200,y=50,width=40,height=40)
def changebg(event):
    #鼠标移到按钮上按钮变红
    event.widget['bg']='red'
def changebg1(event):
    #鼠标离开按钮上按钮变蓝
    event.widget['bg']='blue'
____________
btn1.bind('',changebg1)
root.mainloop()
3.

以下代码实现点击“点我”按钮,弹出信息“give flower”,划线处的代码是?()

import tkinter as tk
import tkinter.messagebox
from tkinter import*
root=Tk()
bt=Button(root)
bt['text']='点我'
bt.pack()
def dianji(event):
    tk.messagebox.showinfo('message','give flower')
bt.bind('<Botton-1>',_______)
root.mainloop()
4.

如下代码创建一个数据库表,表内有几个字段?()

import sqlite3
connection=sqlite3.connect('test.db')
cursor=connection.cursor()
cursor.execute('''CREATE TABLE employees
    (id INTEGER PRIMARY KEY,name TEXT,age INTEGER,salary REAL)''')
connection.close()
5.

在使用 matplotlib 库绘制图形时,如何设置 x 轴和 y 轴的标签?()

6.

以只读方式打开 d:\myfile.txt 文件的代码是?()

7.

以下选项中,创建类正确的是?()

8.

运行以下代码输出的数据为?()

import sqlite3
connection=sqlite3.connect("students.db")
cursor=connection.cursor()
cursor.execute("CREATE TABLE students(name TEXT,age INTEGER)")
cursor.execute("INSERT INTO students VALUES('John',19)")
cursor.execute("INSERT INTO students VALUES('John',18)")
cursor.execute("DELETE FROM students WHERE name='John'")
cursor.execute("INSERT INTO students VALUES('John',17)")
cursor.execute("UPDATE students SET age=22 WHERE name='John'")
cursor.execute("SELECT*FROM students")
results=cursor.fetchall()
for row in results:
    print(row)
connection.close()
9.

执行以下代码,数据表中共有几条数据?()

import sqlite3
conn=sqlite3.connect('student_info.db')
cursor=conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS Student
(id INTEGER PRIMARY KEY,name TEXT,age INTEGER)''')
cursor.execute("INSERT INTO Student(id,name,age)VALUES(1,'Alice',20)")
cursor.execute("INSERT INTO Student(id,name,age)VALUES(2,'Bob',22)")
cursor.execute("INSERT INTO Student(id,name,age)VALUES(3,'Charlie',21)")
cursor.execute("SELECT*FROM Student")
students=cursor.fetchall()
for student in students:
    print(f"ID:{student[0]},Name:{student[1]},Age:{student[2]}")
cursor.execute("UPDATE Student SET age=23 WHERE id=2")
cursor.execute("DELETE FROM Student WHERE id=3")
conn.commit()
conn.close()
10.

下面代码的输出结果正确的是?()

import json
json_str='{"name":"Alice","age":25,"city":"New York"}'
data=json.loads(json_str)
print(data)
11.

以下哪个代码片段用于创建一个 SQLite 数据库 mydatabase 连接?()

12.

运行以下程序,输出结果是?()

class A():
    def__init__(self,x):
        self.x=x
    def add1(self):
        return self.x+self.x
t1=A(3)
t2=A(t1.add1())
print(t2.add1())
13.

程序填空:程序的输出结果如下图所示,程序空白处应该是?()

with open("./text.txt","r",encoding='utf-8')as f:
    a=f.read()
    print(a)

14.

在进行文件读写时,以下为非二进制文件的是?()

15.

要将一个数组[1,2,3,4,5]绘制成折线图,代码是?()

16.

使用 tkinter 模块,下列代码能创建一个输入框的是?()

17.

运行以下程序,输出的结果是?()

class T():
    def__init__(self):
        self.a=1
    def t1(self,b):
        self.a=b+b
c=T()
c.a=c.a+c.a
c.t1(5)
print(c.a)
18.

关于 matplotlib 函数的功能,下列描述错误的是?()

19.

使用 tkinter 设置一个按钮,将按钮放置在窗口最下方,则划线处的代码为?()

from tkinter import*
root=Tk()
root.geometry('300x200')
root.title('my window')
btn1=Button(root,text='按钮 1',bg='red') __________
root.mainloop()
20.

下列关于数据的说法,不正确的是?()

21.

运行以下程序,输出的结果是?()

class F():
    def__init__(self,a):
        self.x=a+1
    def b(self):
        return self.x*self.x
f=F(3)
print(f.b())
22.

有关 JSON(JavaScript Object Notation)的概念,正确的是?()

23.

要生成一个 3*4 的数组,并计算数组中偶数值之和,代码是?()

24.

下面的程序输出结果是"like",请填空?()

25.

下列哪个选项是有效的 JSON 格式?()

判断题 共 10 题
1.

使用 writelines()向文件中写入内容时,写入的内容必须是字符串序列。()

2.

在 JSON 中,可以使用数字作为键的数据类型。()

3.

创建子类时,父类必须包含在本程序中,放置于子类前或子类后都可以。()

4.

如果你想用 numpy 库来计算一个二维数组 a 中每一行的最大值,你可以用 np. max(a,axis=1)来实现。()

5.

使用 with 语句打开文件后,程序发生崩溃时,无法关闭文件。()

6.

Python 创建类时,可以自定义类的名称,按照 Python 变量命名规则命名即可。()

7.

小华想要绘制一个表示某个城市一年内每个月的平均降雨量的折线图,他使用了以下的代码:

import matplotlib.pyplot as plt
months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov"," Dec"]
rainfall=[50,40,60,80,100,120,140,130,110,90,70,60]
plt.plot(months,rainfall)
plt.show()

运行上面这段代码后,会显示一个条形图。()

8.

在 Python 的 tkinter 模块中,常用的控件的有 Canvas、Button、Entry、scatter 等。()

9.

更新"students"表中 id 为 1 的记录的姓名为"Mike"可以使用语句 UPDATE students SET name='Mike'WHERE id=1 实现。()

10.

在 JSON 库中,JSON 格式的数组将被解析为列表。()

C++ 编辑器
输入
输出