2024年3月电子学会青少年软件编程(Python六级)等级考试试卷
客观题
六级
2024
2024-05-01 12:27:55
23次
一、单选题
下面代码的输出结果正确的是?()
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'} |
【知识点】 电子学会Python六级
以下代码实现将鼠标移到按钮上时按钮变红,鼠标移开时按钮变蓝,划线处的代码是?()
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) |
【知识点】 电子学会Python六级
以下代码实现点击“点我”按钮,弹出信息“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 |
【知识点】 电子学会Python六级
如下代码创建一个数据库表,表内有几个字段?()
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 |
【知识点】 电子学会Python六级
运行以下代码输出的数据为?()
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) |
【知识点】 电子学会Python六级
执行以下代码,数据表中共有几条数据?()
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 |
【知识点】 电子学会Python六级
下面代码的输出结果正确的是?()
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'] |
【知识点】 电子学会Python六级
要将一个数组[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() |
【知识点】 电子学会Python六级
使用 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() |
【知识点】 电子学会Python六级
使用 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='') |
【知识点】 电子学会Python六级
要生成一个 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()]) |
【知识点】 电子学会Python六级
二、判断题
小华想要绘制一个表示某个城市一年内每个月的平均降雨量的折线图,他使用了以下的代码:
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.错误 |
【知识点】 电子学会Python六级



