Link for cars.db file :- https://drive.google.com/file/d/1nDMw9lGOelD_eJQcus5uZp
ID: 3904368 • Letter: L
Question
Link for cars.db file :-
https://drive.google.com/file/d/1nDMw9lGOelD_eJQcus5uZp6_KqNqRsET/view?usp=sharing
Question 2 [2 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) In [19]: # YOUR CODE HERE import sqlite3 def cars(): db-sqlite3, connect("cars .db") #establish connection cur-db.cursor() cur.execute("select * from carsales.') #execute query cars cur.fetchall() return cars In [20]: assert cars[0]1719000 Traceback (most recent call last) TypeError kipython-input-20-b6a8861468b9> in () --> 1 assert cars [0] 1719000Explanation / Answer
If you have any doubts, please give me a comment...
fatchall() function returns all tuples in a list
It will look like cars = [(1990, 171900), (1991, 150000)]
cars[0] represents row and you are checking with integer
access through cars[0][1] == 171900
(or)
cars is a function, we can declare it as list
TypeError raises if datatypes are mismatched. i.e., list and integer or etc...
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.