Databases with SQLite · 6 / 15 Exercise Easy

Contact book with SQLite

Objective

Create a Python program that stores contacts in an SQL table and queries them. Use an in-memory database with the sqlite3 module (sqlite3.connect(":memory:")).

Instructions

  • Create the table contacts with two text columns: name and phone.
  • Read an integer n and then n lines with name phone. Insert all the contacts with executemany and ? parameters.
  • Show Contacts: k using SELECT COUNT(*) and then each contact as name: phone, sorted by name (and by phone if the name is repeated).
Input
3
luis 600
ana 611
bea 622
Output
Contacts: 3
ana: 611
bea: 622
luis: 600

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

Start exercise