答案:<pre class="brush:python;toolbar:false">import sqlite3
conn = sqlite3.connect('students.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE 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 WHERE age > 18')
print("年龄大于18岁的学生:")
print(cursor.fetchall())
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()</pre>
解析:
评分标准:
(1)students.db 或等效答案;(2分)
(2)CREATE TABLE 或等效答案; (2分)
(3)WHERE age > 18 或等效答案;(3分)
(4)fetchall() 或等效答案。(3分)