2023年5月电子学会青少年软件编程(Python六级)等级考试试卷
客观题
六级
2023
2023-06-13 16:44:09
39次
一、单选题
执行数据库操作的部分代码如下:
import sqlite3
db = sqlite3.connect("test.db")
cur=db.cursor()
cur.execute("create table Student(Sname char(20),Sage SMALLINT);")
db.close()下列描述正确的是?( )
| A. 当前操作的数据库的名称为Student |
B. create table语句的功能是数据库查询 |
| C. 数据表中将会插入2条新记录 |
D. 当前表中有2个字段 |
【知识点】 电子学会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.writerows(rows) # ④关于上述语句的解释,不正确的是?( )
| A. ①处功能为导入csv 库 |
B. ②处以写方式打开文件 |
| C. ③处创建 csv.writer 实例 |
D. ④处一次只能写入一行 |
【知识点】 电子学会Python六级
小张近阶段要学习的英文单词存储在“data.txt”文件,格式如图所示。

处理“data.txt”文件中英文单词的Python程序段如下:
file = open("data.txt")
for word in file:
if word[0:1] == "c":
continue
else:
print(word)
file.close()下列关于该程序段的功能,说法正确的是?( )
| A. 输出包含"c"(区分大小写)的单词 |
B. 输出以"c"开头(区分大小写)的单词 |
| C. 输出以"c"开头(不区分大小写)的单词 |
D. 输出不是以"c"开头(区分大小写)的单词 |
【知识点】 电子学会Python六级
有如下程序段:
class Student:
count = 0
def __init__(self, name):
self.name = name
Student.count += 1
def study(self):
print(f'{self.name}在学习')
student1 = Student("小明")
student2 = Student("小红")
student2.study()执行代码后,下列说法不正确的是?( )
| A. 程序创建了2个实例 |
B. Student.count的值为0 |
| C. study为该类的方法 |
D. 输出的结果为“小红在学习” |
【知识点】 电子学会Python六级
在中国,具有中国国籍且年满18周岁的人拥有选举权利,学校想要统计出截止到2022年12月31日年满18周岁的学生名单。
学生的相关信息存储在"stu_info.txt"文件中,存储格式如下:
高一 1|谢乐|340421200606155914
高一 1|岑新奇|330282200407301529
用python编写代码如下:
f=open("stu_info.txt","r",encoding="utf8")
namelist=[ ] #存放年满18周岁的学生名单
for line in f.readlines():
stu=line.split("|")
birth= ①
if birth<="20041231":
namelist.append( ② )
print(namelist)①②两处的代码应填为?( )
| A. ① stu[2][6:14] ② stu[1] |
B. ① stu[2][6:13] ② stu[1] |
| C. ① stu[3][6:14] ② stu[2] |
D. ① stu[2][-12:-1] ② stu[1] |
【知识点】 电子学会Python六级
利用tkinter模块设计一个求“圆面积”的界面,程序中自定义了若干个功能函数和按钮,要求点击“退出”按钮能关闭界面窗口,点击“重置”按钮能重置输入框中的数据,部分程序代码如下:
def cancel():
var_r.set('')
def tc_quit():
win.quit()
win.destroy()以下哪个选项可以在“退出”按钮中正确调用功能函数?( )
| A. btn_Cancel=tk.Button(win,text='重置',command=tc_quit) |
B. btn_quit=tk.Button(win,text='退出',command=cancel) |
| C. btn_quit=tk.Button(win,text='退出',command=tc_quit) |
D. tc_quit=tk.Button(win,text='退出') |
【知识点】 电子学会Python六级
有如下程序段:
class xcal: def __init__(self,numx,numy): self.numx=numx self.numy=numy def xadd(self,another): numx=self.numx*another.numx numy=self.numy*another.numy return xcal(numx,numy) def print(self): print(str(self.numx)+"/"+str(self.numy)) x=xcal(2,3)
y=x.xadd(xcal(4,5))
y.print()
程序运行后,输出的结果是?( )
| A. 6/20 |
B. 15/8 |
| C. 10/12 |
D. 8/15 |
【知识点】 电子学会Python六级
用Python语句创建sQLite数据库,代码如下:
import sqlite3
conn= sqlite3.connec("test2.db")
c=conn.cursor()
c.execute("CREATE TABLE STUDENTS(ID INT,AGE INT,NAME TEXT)")
c.execute("INSERT INTO STUDENTS(ID, AGE,NAME) VALUES(2,16,'LISA')")
c.execute("UPDATE STUDENTS set AGE=18 where it,ID=2")
conn.commit()
c.close()
conn.close()程序运行后,AGE列的值是?( )
| A. 2 |
B. 16 |
| C. LISA |
D. 18 |
【知识点】 电子学会Python六级
小李设计一个显示加、减、乘、除的单选框界面,代码如下:
import tkinter
from tkinter import *
root = Tk()
v = IntVar()
calcs = [ ('+', 1), ('-', 2), ("*", 3), ("/", 4),]
for calc, num in calcs:
# 设置单选框,用来显示运算符
Radiobutton(text = calc,variable =v,value=num).grid(row=num-1, column=1)
root.mainloop()运行后的界面是?( )
| A.
|
B.
|
| C.
|
D.
|
【知识点】 电子学会Python六级
Python程序如下:
from random import random a=[0]*7 flag=[False]*10 i=1 while i<=6: a[i]=int(random()*5)*2+1 if flag[a[i]]==False or a[i]>a[i-1]: flag[a[i]]=True i=i+1
该程序段运行后,列表a的值可能为?( )
| A. [0, 7, 5, 9, 7, 1, 7] |
B. [0, 1, 3, 5, 7, 9, 1] |
| C. [0, 9, 2, 3, 5, 7, 5] |
D. [0, 9, 5, 9, 7, 9, 1] |
【知识点】 电子学会Python六级






