Discuss / Python / SQLite交作业

SQLite交作业

Topic source
def get_score_in(low, high):
	try:
		conn = sqlite3.connect('test.db')
		cursor = conn.cursor()
		cursor.execute('select * from user where ? <= score and ? >= score',(low,high))
		values = cursor.fetchall()
	except BaseException as e:
		print('error')
	finally:
		' 返回指定分数区间的名字,按分数从低到高排序 '
		values = sorted(values, key= lambda n:n[2])
		cursor.close()
		conn.close()
		return [x[1] for x in values]

  • 1

Reply