Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Part 1:

To create the database and add data programmatically by using the Insert query, we can use SQL
statements within a Python script. Here's an example code snippet:

import sqlite3

# Connect to the database

conn = sqlite3.connect('books.db')

# Create a cursor object

c = conn.cursor()

# Create the books table

c.execute('''CREATE TABLE books

(title text, author text, price real)''')

# Add some data to the books table

c.execute("INSERT INTO books VALUES ('The Great Gatsby', 'F. Scott Fitzgerald', 10.99)")

c.execute("INSERT INTO books VALUES ('To Kill a Mockingbird', 'Harper Lee', 7.99)")

c.execute("INSERT INTO books VALUES ('1984', 'George Orwell', 12.99)")

c.execute("INSERT INTO books VALUES ('Pride and Prejudice', 'Jane Austen', 9.99)")

# Commit the changes

conn.commit()

# Close the connection

conn.close()

You might also like