Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 2 12 points] Write Python code that reads from cars.db and produces a l

ID: 3903721 • Letter: Q

Question

Question 2 12 points] Write Python code that reads from cars.db and produces a list, cars , which contains the number of German passenger cars sold in the US The table was created using the following SQL command CREATE TABLE carsales (year INTEGER, sales INTEGER) The values were then inserted (in chronological order) as.: INSERT INTO carsales (year, sales) VALUES (1990, 171900) INSERT INTO carsales (year, sales) VALUES (1991, 150000) And so on (up to the year 2009) 15): # YOUR CODE HERE 16]: assert cars[] - 1719006

Explanation / Answer

import sqlite3

try:

conn=sqlite3.connect("cars.db") #establish connection

cur=conn.cursor()

cur.execute("select * from carsales") #execute query

cars=[]

results=cur.fetchall()

for row in results:

cars.append(row[1])

except Exception as e:

print(e)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote