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

2024年3月电子学会青少年软件编程(Python六级)等级考试试卷
客观题 六级 2024 2024-05-01 12:27:55 23

一、单选题

1.

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

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

["name":"Alice","age":25,"city":"New York"]

B.

{'name':"Alice",'age':25,'city':"New York"}

C.

{"name":"Alice","age":25,"city":"New York"}

D.

{'name':'Alice','age':25,'city':'New York'}

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()
A.

btn1.bind()

B.

btn1.bind('<Enter>',changebg)

C.

btn1.bind('<Enter>',changebg1)

D.

btn1.bind('<Button-1>',changebg1)

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()
A.

root

B.

dianji

C.

def

D.

give flower

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()
A.

3

B.

4

C.

5

D.

6

5.

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

A.

plt.title()和 plt.legend()

B.

plt.set_xlabel()和 plt.set_ylabel()

C.

plt.xlabel()和 plt.ylabel()

D.

plt.xticks()和 plt.yticks()

6.

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

A.

f=open("d:\\myfile.txt")

B.

f=open("d:\\myfile.txt","rt+")

C.

f=open("d:\\myfile.txt","r+")

D.

f=open("d:\\myfile.txt","a")

7.

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

A.

class test1:

    def prt(self):

    ……

B.

class Mg():

    def__init__(na,ag):

        self.na=na

C.

class A():

    def print(self):

        print("Yes")

a=A()

a. print()

D.

class 3Point:

    def__init__(self):

    ……

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()
A.

('John',22)

B.

('John',18)

C.

('John',19)

D.

('John',17)

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()
A.

2

B.

3

C.

4

D.

5

10.

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

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

{"name":"Alice","age":25,"city":"New York"}

B.

{'name':'Alice','age':25,'city':'New York'}

C.

[{'name':'Alice','age':25,'city':'New York'}]

D.

['name':'Alice','age':25,'city':'New York']

11.

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

A.

'connection=sqlite3.connection("mydatabase.db")'

B.

'connection=sqlite3.connect("mydatabase.db")'

C.

'connection=sqlite3.open("mydatabase.db")'

D.

'connection=sqlite3.connect("mydatabase.txt")'

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())
A.

10

B.

12

C.

程序报错

D.

6

13.

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

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

A.

10

B.

11

C.

9

D.

12

14.

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

A.

timu.docx

B.

timu.mp4

C.

timu.txt

D.

timu.jpg

15.

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

A.

import matplotlib.pyplot as plt

plt.plot([1,2,3,4,5])

plt.show()

B.

import numpy as np

import matplotlib.pyplot as plt

plt.plot(np.array(1,5))

plt.show()

C.

import matplotlib.pyplot as plt

plt.bar([1,2,3,4,5])

plt.show()

D.

import matplotlib.pyplot as plt

plt.scatter([1,2,3,4,5])

plt.show()

16.

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

A.

from tkinter import*

root=Tk()

root.title("test")

e1=Entry(root)

e1.pack()

root.mainloop()

B.

from tkinter import*

root=Tk()

root.title("test")

e1=Button(root)

e1.pack()

root.mainloop()

C.

from tkinter import*

root=Tk()

root.title("test")

e1=Label(root,text='123')

e1.pack()

root.mainloop()

D.

from tkinter import*

root=Tk()

root.title("test")

e1=Checkbutton(root,text='123')

e1.pack()

mainloop()

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

2

B.

12

C.

10

D.

6

18.

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

A.

bar()函数用于绘制垂直柱形图

B.

plot()函数用于绘制线形图

C.

barh()函数用于绘制饼形图

D.

scatter()函数用于绘制散点图

19.

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

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

btn1.pack(side=TOP)

B.

btn1.pack()

C.

btn1.pack(side=BOTTOM)

D.

btn1.pack(side='')

20.

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

A.

一维数据可由列表表示,也可用集合表示

B.

二维数据由多个一维数据构成

C.

二维数据可由二维列表表达,也可由表格或 csv 格式的文件表达

D.

一维数据采用线性方式组织,是有序的

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())
A.

4

B.

8

C.

16

D.

20

22.

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

A.

是一种数据交换格式

B.

是一种编程语言

C.

是一种数据库

D.

是一种算法

23.

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

A.

import numpy as np

arr=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])

np.sum(arr[arr%2==0])

B.

import numpy as np

arr=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])

np.sum(arr[:,arr%2==0])

C.

import numpy as np

arr=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])

np.sum(arr[np.get(arr%2==0)])

D.

import numpy as np

arr=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])

np.sum(arr[arr.even()])

24.

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

A.

2,0

B.

2,1

C.

2,2

D.

0,2

25.

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

A.

{'name':'Alice','age':25,'city':'New York'}

B.

{'name':'Alice','age':25,'city':'New York'}

C.

{"name":"Alice",age:25,city:'New York'}

D.

{"name":"Alice","age":25,"city":"New York"}

二、判断题

1.

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

A.正确 B.错误
2.

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

A.正确 B.错误
3.

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

A.正确 B.错误
4.

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

A.正确 B.错误
5.

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

A.正确 B.错误
6.

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

A.正确 B.错误
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()

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

A.正确 B.错误
8.

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

A.正确 B.错误
9.

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

A.正确 B.错误
10.

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

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