Databases with SQLite · 7 / 15 Exercise Easy

Filter by price

Objective

Create a Python program that selects, with a WHERE query, the products that cost at least a minimum price. Use an in-memory database with the sqlite3 module (sqlite3.connect(":memory:")).

Instructions

  • Create the table products with the columns product (text) and price (integer).
  • Read n and then n lines with product price. Then read the minimum price.
  • Run SELECT ... WHERE price >= ? with the minimum as a parameter ?. Sort from most to least expensive and, in case of a tie, by name.
  • Show each result as product: price and at the end Found: k.
Input
4
pan 2
leche 3
queso 8
vino 12
5
Output
vino: 12
queso: 8
Found: 2

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

Start exercise