Python SQLite Homework
For this assignment you will write a Python program which prints information about a customer in the Chinook database.
Write your program in the provided file customer_info.py
. You will need to copy the chinook.sqlite
database file that you constructed for the last assignment into the directory for this assignment. However, when you submit you should only add your changes to customer_info.py
to the git repository.
Here is the official documentation for the sqlite3
module: https://docs.python.org/3/library/sqlite3.html
Requirements
Your program must ask the user for a customer ID number. If there is no customer with that ID number, print a message saying so. If there is a customer with that ID number, select and print the following information:
- First and last name of the customer
- Email address of the customer
- The artist and track names of all the tracks that the customer has purchased, ordered by artist name and then track name
- The customer support representitive for the customer
In the example programs we looked at in class I only ran one query and then looped over all the rows of the result. For this assignment it will be best to run two separate queries. The first to get the name, email, and support representative of the company, and another to get the tracks. The first query will only return one row if the customer exists, since there can only be one customer with any given customer ID. So for this query you can use fetchone()
which will either return one row of the result, or None
if there are no rows. See the sqlite3
documentation linked above for more information.
Here is an example run of my solution:
Enter customer ID: 1
Luís Gonçalves
luisg@embraer.com.br
Tracks purchased:
Academy of St. Martin in the Fields & Sir Neville Marriner - Fantasia On Greensleeves
Battlestar Galactica (Classic) - Experiment In Terra
Battlestar Galactica (Classic) - Take the Celestra
Berliner Philharmoniker & Hans Rosbaud - Karelia Suite, Op.11: 2. Ballade (Tempo Di Menuetto)
Chico Science & Nação Zumbi - Interlude Zumbi
Chico Science & Nação Zumbi - Lixo Do Mangue
Chico Science & Nação Zumbi - Rios Pontes & Overdrives
Cidade Negra - A Cor Do Sol
Cidade Negra - Doutor
Cidade Negra - Podes Crer
Cláudio Zoli - Linha Do Equador
Frank Zappa & Captain Beefheart - Carolina Hard-Core Ecstasy
Guns N' Roses - Back off Bitch
Guns N' Roses - Coma
Guns N' Roses - Don't Cry (Original)
Guns N' Roses - Garden of Eden
Guns N' Roses - Rocket Queen
Guns N' Roses - Think About You
Kiss - Calling Dr. Love
Kiss - Cold Gin
Kiss - Shout It Out Loud
Kiss - Strutter
Led Zeppelin - Communication Breakdown(2)
Marcos Valle - Água de Beber
Os Paralamas Do Sucesso - Cinema Mudo
Os Paralamas Do Sucesso - Mensagen De Amor (2000)
Os Paralamas Do Sucesso - Meu Erro
Os Paralamas Do Sucesso - Saber Amar
Os Paralamas Do Sucesso - Será Que Vai Chover?
Os Paralamas Do Sucesso - Vamo Batê Lata
Ozzy Osbourne - Flying High Again
Ozzy Osbourne - Mama, I'm Coming Home
Ozzy Osbourne - Paranoid
U2 - All Along The Watchtower
Various Artists - Ipiranga 2001
Various Artists - Reggae Tchan
Various Artists - TriboTchan
Various Artists - X-9 2001
Support representitive: Jane Peacock
And with a non-existant ID:
Enter customer ID: 10000
There is no customer with ID 10000
To stay PEP8 compliant, you will need to split long queries onto multiple lines. There are a number of ways to do this. One way is to enclose a query in triple quotes, which allows multiline strings:
Alternatively, if multiple strings are within parentheses without commas between them, they will be concatenated into a single string, even if it spans multiple lines. For example:
Note the space before the single quote on the first line. This is necessary because the two strings on separate lines will be concatenated together.
Submission
Submit only your changes to customer_info.py
, do not submit the database file.
For full credit you must adhere to the requirements above, and your code must be PEP8 compliant. PEP8 will be checked automatically, the correctness of your code will be checked manually.