2024年9月电子学会青少年软件编程(Python六级)等级考试试卷
客观题
六级
2024
2024-11-15 13:21:30
110次
一、单选题
从一个json文件中读取一些数据,并将其转换为Python的字典对象。可以使用json模块中的load方法来实现这个功能。请问,下面哪个选项是正确的代码,可以从data.json文件中读取数据,并赋值给变量data?( )
| A. data = json.load(open('data.json')) |
B. data = json.loads('data.json') |
| C. data = open('data.json').load(json) |
D. data = open('data.json').loads(json) |
【知识点】 电子学会Python六级
运行以下代码:
import tkinter as tk def change_text(): label.config(text="Changed text") root = tk.Tk() label = tk.Label(root, text="Original text") label.pack() button = tk.Button(root, text="Change text", command=change_text) button.pack() root.mainloop()
当点击“Change text”按钮后,标签的文本会变成?( )
| A. 保持不变 |
B. "Changed text" |
| C. "Button clicked!" |
D. "Original text" |
【知识点】 电子学会Python六级
以下代码中,哪个选项可以正确地创建一个类和其实例?( )
| A. class MyClass(): pass my_instance = MyClass('ok') |
B. class MyClass(): def __init__(self): print('hello') my_instance = MyClass() |
| C. class MyClass(): x = 10 my_instance = MyClass(x) |
D. def MyClass(): print("This is a method") my_instance = MyClass() |
【知识点】 电子学会Python六级
下面代码的输出结果正确的是?( )
import numpy as np
student = np.dtype([('name','S20'), ('age', 'i2'),('height', 'f4')])
a = np.array([('Alice', 20, 55),('Jone', 21, 48)], dtype = student)
print(a) | A. [(b'Alice', 20., 55.) (b'Jone', 21., 48.)] |
B. [(b'Alice', 20., 55) (b'Jone', 21., 48)] |
| C. [(b'Alice', 20, 55.) (b'Jone', 21, 48.)] |
D. {(b'Alice', 20, 55.), (b'Jone', 21, 48.)} |
【知识点】 电子学会Python六级
下列代码创建了一个按钮,当按钮被点击时,会发生什么?( )
import tkinter as tk
def on_button_click():
print("Button clicked!")
root = tk.Tk()
button = tk.Button(root, text="Click me!", command=on_button_click)
button.pack()
root.mainloop() | A. 弹出对话框显示"Button clicked!" |
B. 在控制台输出"Button clicked!" |
| C. 窗口标题变为"Button clicked!" |
D. 按钮文本变为"Clicked!" |
【知识点】 电子学会Python六级
有一个名为scores.txt的文件,里面存储了一些学生的姓名和成绩,如下所示:
Alice 90
Bob 80
Charlie 85
David 75
Eve 95
你想用Python读取这个文件,并将每一行的数据格式化为一个元组,例如('Alice','90'),请补全下面的代码?( )
with open('scores.txt', 'r') as f:
for line in f:
# 将每一行的数据格式化为一个元组
score = tuple(_______)
print(score)
| A. line.split() |
B. line.strip() |
| C. line.split(',') |
D. line.strip(',') |
【知识点】 电子学会Python六级




