创建学生库
题目说明
import sqlite3
conn = sqlite3.connect(' ① ')
cursor = conn.cursor()
cursor.execute(''' ② students_table(id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,age INTEGER,grade TEXT)''')
students = [ ('Alice', 17, '10th'), ('Bob', 18, '11th'), ('Charlie', 16, '10th'), ('David', 19, '12th'),('Eve', 17, '11th')]
cursor.executemany('''INSERT INTO students_table (name, age, grade) VALUES (?, ?, ?)''', students)
conn.commit()
cursor.execute('SELECT * FROM students_table ③ ')
print("年龄大于18岁的学生:")
print(cursor. ④ )
cursor.execute('UPDATE students_table SET age = age + 1 WHERE name = "Alice"')
cursor.execute('DELETE FROM students_table WHERE name = "Bob"')
conn.commit()
conn.close()
评分标准
(1)students.db 或等效答案;(2分) (2)CREATE TABLE 或等效答案; (2分) (3)WHERE age > 18 或等效答案;(3分) (4)fetchall() 或等效答案。(3分)
本题为编程题,提交代码并运行通过测试点后判分。
正在加载题目数据…
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析