2022年12月电子学会青少年软件编程(Python六级)等级考试试卷
客观题
六级
2022
2023-01-10 09:34:32
57次
一、单选题
下列代码的执行结果是?(?)
import numpy as np a = np.arange(9, dtype = np.float_).reshape(3,3) b = np.array([100,10,10]) print (np.divide(a,b))
| A. [[0. 0.1 0.2 ] [0.03 0.4 0.5 ] [0.06 0.7 0.8 ]] |
B. [[0. 0.01 0.2 ] [0.3 0.04 0.5 ] [0.6 0.07 0.8 ]] |
| C. [[0. 0.1 0.02 ] [0.3 0.4 0.05 ] [0.6 0.7 0.08 ]] |
D. [[0. 0.01 0.2 ] [0.03 0.04 0.5 ] [0.06 0.07 0.8 ]] |
【知识点】 电子学会Python六级
以下代码的运行结果是?(?)
class Num():
def __init__(self,a,b,c):
self.a=a
self.b=b
self.c=c
def run(self):
print(self.a*10)
print(self.b*5)
print(self.c*2)
e = Num('C','BB','AAA')
e.run() | A. AAAAAAAAAA BBBBBBBBBB CCCCCC |
B. AAAAAAAAAA BBBBB CC |
| C. CCCCCCCCCC BBBBBBBBBB AAAAAA |
D. CCCCCCCCCC BBBBB AA |
【知识点】 电子学会Python六级
有Python程序段如下,下列选项错误的是?(?)
class Car(): def __init__(self,name,color): self.name=name self.color=color def run(self): print(self.color +self.name+"is running")
| A. 使用class关键字来定义一个Car类,类名的首字母必须要大写 |
B. 方法__init()__定义了三个参数:self、name和color,其中self参数可省略 |
| C. 语句“self.color=color”获取存储在参数color中的值并存储到self的属性color中 |
D. Car类还定义了一个方法run() |
【知识点】 电子学会Python六级
import tkinter as tk
window = tk.Tk()
window.title('Mywindow')
window.geometry('200x100')
var = tk.StringVar()
p= tk.Label(window,textvariable=var,bg='green',font=('Arial', 12),width=15, height=2)
p.pack()
on_hit = False
def hit_me():
global on_hit
if on_hit == False:
on_hit = True
var.set('You hit me!')
else:
on_hit = False
var.set('I Love Python!')
b=tk.Button(window, text='点我', width=15, height=2,command=hit_me)
b.pack()
window.mainloop()运行如上代码,对按钮点击二次后,在文本框中显示的文字为?(?)
| A. You hit me! |
B. I Love Python! |
| C. You hit me! I Love Python! |
D. I Love Python! You hit me! |
【知识点】 电子学会Python六级
有如下Python程序:
class Car():
def __init__(self,name,color):
self.name=name
self.color=color
def run(self):
print(self.color+self.name+'is running')
class Bus(Car):
def __init__(self,name,color):
super().__init__(name,color)
car1=Bus('公交车','红色')
car1.run()上述代码描述了面向对象的哪个特征?(?)
| A. 封装 |
B. 继承 |
| C. 多态 |
D. 隐藏 |
【知识点】 电子学会Python六级
有如下程序代码:
import csv
headers = ['学号','姓名','分数']
rows = [('202001','张三','98'),
('202002','李四','95'),
('202003','王五','92')]
with open('score.csv','w',encoding='utf8',newline='') as f :
writer = csv.writer(f)
writer.writerow(headers)
writer.writerow(rows)下列说法不正确的是?(?)
| A. 在相同路径下生成一个score.csv文件 |
B. f是一个文件对象 |
| C. headers 是字段名称 |
D. writer.writerow(rows)将写入多行数据 |
【知识点】 电子学会Python六级
数据文件“abc.txt”中包含若干个英文单词,如图所示:

读取文件“abc.txt”中数据的Python程序段如下:
file = 'abc.txt' word_b = [] for word in open(file): if word[0:1] = = 'a' and len(word)>4: word_b.append(word)
该程序段执行后,列表word_b中的数据为?(?)
| A. 文件“abc.txt”中所有包含字母“b”且长度大于4的单词 |
B. 文件“abc.txt”中所有首字母为“a”且长度大于4的单词 |
| C. 文件“abc.txt”中所有第2个字母为“a”且长度大于4的单词 |
D. 文件“abc.txt”中所有第1、2个字母均为“a”且长度大于4的单词 |
【知识点】 电子学会Python六级
有如下程序代码:
import json
s = '''[{"name":"kingsan","age":23},
{"name":"xiaolan","age":22}]
'''
print(type(s))
data = json.loads(s)
print(data)
print(type(data))下列说法正确的是?(?)
| A. s的数据类型是list |
B. data的数据类型是字符串 |
| C. loads()用于将字符串转化为JSON对象 |
D. JSON数据可以用双引号来包围,也可以用单引号 |
【知识点】 电子学会Python六级
小林编写一段文件读写操作代码,文件如下图,代码段如下:

file=open('ceshi.txt','w')
file.write("python is a programming language.")
file.close( )
file=open('ceshi.txt','r')
print(file.read( ))该代码段运行后,输出的结果为?(?)
| A. IA Distributed System Based on Python. |
B. python is a programming language. |
| C. IA Distributed System Based on Python. python is a programming language. |
D. 程序编译错误,不会输出结果 |
【知识点】 电子学会Python六级
文件“score2.csv”中存放了3位同学的成绩数据,内容如图所示,小李编写了如下程序:

csv_file = open("score2.csv","r")
flines = csv_file.readlines()
csv_file.close()执行程序后,flines的结果是?(?)
| A. ['202008480,18', '202008319,19', '2202008333,20'] |
B. ['202008480,18\n', '202008319,19\n', '2202008333,20\n'] |
| C. ['准考证号,成绩', '202008480,18', '202008319,19', '2202008333,20'] |
D. ['准考证号,成绩\n', '202008480,18\n','202008319,19\n','2202008333,20\n'] |
【知识点】 电子学会Python六级
执行下列代码,说法错误的是?(?)
import sqlite3
DATABASE = 'data.db'
db = sqlite3.connect(DATABASE)
cur = db.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS list(id INTEGER PRIMARY KEY autoincrement, name text)")
db.commit()
cur.execute("SELECT COUNT(*) FROM list")
if cur.fetchall()[0][0] == 0:
cur.execute('INSERT INTO list(id,name) VALUES(1,"lilei")')
db.commit() | A. data.db文件中有一张名为list的数据表 |
B. list数据表中有两个字段id和name |
| C. list数据表中没有记录 |
D. 去掉最后一行的db.commit(),对程序有影响 |
【知识点】 电子学会Python六级

