Command Palette

Search for a command to run...

Hectal
Phase 15: Python for APIs, Services and Tools
Python · Exercise 4 of 6 PreviousNext
Intermediate

A parameterised query

Write find_users(conn, plan). conn is an open sqlite3 connection to a database with a table users(id, name, plan). Return a list of the names (just the text) of all users whose plan equals the given one, sorted alphabetically. If nobody matches, return [].

The plan value must be passed as a parameter (a ? placeholder), not pasted into the SQL text.

What Check tests

  1. returns sorted names for a plan
  2. returns an empty list for an unknown plan
  3. a plan containing a quote does not break the query
  4. text that looks like SQL is only data
  5. the SQL uses a placeholder

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.