2023年12月电子学会青少年软件编程(Python六级)等级考试试卷
操作/编程
六级
2023
2024-01-05 20:54:04
103次
一、编程题
学生表操作题
建立学生表,将学号设置为主键,实现对数据的添加和查找。(无需运行通过,写入代码即可)
import sqlite3
con = sqlite3. ① ('./student.db')
cur = ②
sql ='''
③ IF NOT EXISTS Stu (
id INTEGER ④ AUTOINCREMENT,
name TEXT,
age INTEGER,
clas TEXT)
'''
cur.execute(sql)
con.commit()
sql = '''
⑤ (name,age,clas) VALUES(?,?,?)
'''
cur.execute(sql,('张三',16,'二三班'))
con.commit()
【知识点】 电子学会Python六级
编写一个类`Circle`,包含两个属性`radius`和`color`,以及四个方法`get_area()`、`get_circumference()`、`get_diameter()`和`print_info()`,分别用于计算圆面积、圆周长、圆直径,并打印出圆的半径和颜色。
代码如下,请补全代码。
class Circle:
def __init__(self, radius, color):
①
self.color = color
def get_area(self): #圆面积
return ②
def get_circumference(self): #圆周长
return ③
def get_diameter(self):
return 2 * self.radius
def print_info(self):
print("Radius:", self.radius)
print("Color:", self.color)
circle = Circle(5, "red")
④ #输出圆的半径和颜色
print("Area:", circle.get_area())
print("Circumference:", circle.get_circumference())
print("Diameter:", circle.get_diameter())
【知识点】 电子学会Python六级
统计单词问题
统计英文文本中出现的不同单词个数:读取只包含英文和标点的文件'/data/abc.txt',文件中单词和单词之间用1个空格或标点符号隔开,文末以标点符号结尾,在区分单词大小写的情况下,输出该文本中所出现的不同单词个数。
实现上述功能的Python程序如下,请在划线处填入合适的代码。
f=open('/data/ ① ','r')
text=f.read()
lst=[]
s=""
def judge( ② ):
if st in lst:
return False
else:
return True
for i in range(len(text)):
c= ③
if"a"<=c<="z" or"A"<=c<="Z":
s=s+c
else:
if judge(s):
lst.append(s)
s=""
print("出现的不同单词个数为:",len(lst))
【知识点】 电子学会Python六级
