Databases with SQLite · 11 / 15 Exercise Medium

Paged ranking

Objective

Create a Python program that shows a ranking in pages using LIMIT and OFFSET in the query. Use an in-memory database with the sqlite3 module (sqlite3.connect(":memory:")).

Instructions

  • Create the table ranking with player (text) and points (integer). Read n lines with player points and store them.
  • Read the page size and the page number (starts at 1). The total number of pages is n / size rounded up.
  • Show Page p of t. Then query the players sorted by points descending (and by name on ties), with LIMIT and OFFSET as parameters.
  • Show each row as position. player - points points, where the position follows the global numbering of the ranking.
Input
5
zoe 50
ana 70
leo 50
bea 90
mia 10
2
2
Output
Page 2 of 3
3. leo - 50 points
4. zoe - 50 points

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise