Question: In Python using sqlite3 These are the contents of the .db file: import sqlite3 # sqlite3.connect creates a file named 'lab7.db' on the system. connection

In Python using sqlite3

These are the contents of the .db file:

import sqlite3 # sqlite3.connect creates a file named 'lab7.db' on the system. connection = sqlite3.connect('lab7.db') # The cursor is the control structure that traverses records in the database. cursor = connection.cursor() cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Hurricane Jelly Beans','jelly beans','abc123', '1.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Typhoon Model Boat','plastic model boat', 'abc456', '12.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Supermarine Spitfire', 'plastic model airplane', 'bcd123', '3.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('ENIAC', 'model of first computer', 'bcd456', '21.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Toyota', 'Corrolla', 'gas2013', '1.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Ford', 'Escape', 'hybrid2008', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Ford', 'Fusion', 'hybrid2017', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Kia', 'forte', 'gas2014', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Cadillac', 'Escalade', 'gas2014', '3.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Honda', 'accord', 'gas2014', '7.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Honda', 'civic', 'hybrid2017', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Ford', 'explorer', 'gas2016', '3.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Hyundai', 'sonata', 'gas2014', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Rolls Royce', 'phantom', 'gas2018', '4.00')) # Commit the changes connection.commit()

Create and run the following script to display all of the records in your lab7.db. Complete all of the TODOs.

# TODO import sqlite3 import sqlite3 # TODO Create a sqlite3 connection to the lab7.db database file that # was created in Section 4 conn = sqlite3.connect('lab7.db')

# TODO Using the connection you created in the previous step, create a cursor cur = conn.cursor() # TODO Using the cursor, execute an SQL statement that selects # all of the records from the products table with this SQL: SELECT * FROM products all = cur.execute('SELECT * FROM products')

# TODO Display all of the records in columns. You MUST use the str.format() # method to print the data in columns for row in all: ##################################### ########## YOUR CODE ############### ########## GOES HERE ############### #####################################

stuck on the last part to display the columns using str.format()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!