IT 117: Intermediate Scripting
Answers to Class 16 Ungraded Quiz


  1. What is the name of the module that allows Python to work with a SQLite database?
    sqlite3
  2. What would you enter at the command line if you wanted a SQLite command line that let you work with the database contained in the file work.db?
    sqlite3 work.db
  3. If you were writing a Python script that needed to work with a SQLite database what is the first thing you would have to create?
    a connection object to the database
  4. Write the Python statement that would create the thing mentioned above on the SQLite file work.db.
    con = sqlite3.connect("work.db")
  5. Once you have the thing mentioned above, what is the next thing you have to create?
    a cursor object
  6. Write a Python statement that creates this thing.
    cur = con.cursor()
  7. What must you do to make sure the changes you have made to a table are saved?
    commit the changes
  8. Write the Python statement to perform the action mentioned above.
    con.commit()
  9. Write the Python statement to run the query
    select * from students
    using the cursor cur.
    cur.execute("select * from students")
  10. Write the Python statements to print the results of the previous query.
    for row in cur:
        print(row)