基于score.db数据库(数据表scores:id、nam
类型:程序题

基于score.db数据库(数据表scores:id、name、grade、class),实现修改指定学生成绩、统计各班优秀人数(grade>90)、格式化输出功能,补全代码。 (本题无需运行通过,写入代码即可)

import sqlite3
# 连接数据库
conn = sqlite3.connect("score.db")
cursor =        ①
# 任务1:修改2班李四的成绩为95
update_sql = "UPDATE scores SET grade = ? WHERE class = ? AND name = ?"
cursor.execute(update_sql, (95, "2班", "李四"))
②          # 提交数据修改
# 任务2:统计各班成绩优秀人数
cursor.execute("SELECT class FROM scores WHERE grade > 90")
res =         ③          # 获取全部查询结果
count_dict = {}
for row in res:
cls = row[0]
    if cls in count_dict:
        count_dict[cls] += 1
    else:
                ④
# 任务3:格式化输出
print("各班优秀学生统计:")
for cls, num in count_dict.items():
print(f"{cls}:{num}人")
# 关闭资源
⑤
conn.close()
代码编辑器 加载中...
留空使用题目默认限制
{{resultStatus.text}}
正在加载运行记录...
乐编题库AI助手
人工客服
微信扫码联系客服
历史对话
{{ s.title || '未命名对话' }}
{{ s.created_at }}
暂无历史对话
我能帮助你什么?