Question: In this assignment, you'll practice accessing data in sqlite 3 database using Python. We will use a database of Pokemon as an example. Use the
In this assignment, you'll practice accessing data in sqlite database using Python. We will
use a database of Pokemon as an example.
Use the following codes as the basis for this exercise.
import sqlite
# create connection and cursor
conn sqlite connect 'pokemon.db
cursor conn. cursor
# execute SQL query. In this example, show all data in pokemonmeta table
cursor.executeSELECT from pokemonmeta
rowscursor.fetchall
# print the column names of the table
header
for columninfo in cursor.description:
headercolumninfo
printheader
#print the table content
for row in rows:
printrow
#close connection after using it
conn.close
In the sample codes, cursor. description provides the column names of the last query
cursorexecuteSELECT from pokemonmeta in our case cursor.description returns a
list of tuple that contains the column information, and the first element of the tuple is the
name of the column. Hence when we iterate through the coursor.description list with
columninfo in the first forloop, columninfo refers to the tuples in the list one by one, and
columninfo refers to the name of a column
The program above reads from a table named pokemonmeta and show all the content of
the table.
Task
points Extend the program so that it shows a list of all water pokemons instead of all
pokemons. Note either type or type can be "water". So the SQL command to be
used can be something like:
SELECT from eta WHERE 'fire'
'fire'
Your output should look like the following with headings:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
