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 sqliteconnect pokemondb
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
print header
#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
Currently, the table did not reflect the fact that Squirtle can evolve into Wartortle, and
Wartotle evolve into Blastoise
points Extend the program, so that it updates the pokemonmeta table, so that the
evolveinto column reflects the correct evolution relationship between Squirtle,
Wartortle, and Blastoise.
You will need to use update command for Squirtle and Wartortle. For example for
Squirtle:
UPDATE pokemonmeta set evolveto'Wartortle' WHERE
name Squirtle'
Don't forget to commit the changes
point print out the updated records for Squirtle, Wartortle, and Blastoise to double
check your results.
Your output should look like the following with headings:
name, eight, base height, catch chance, base candy type, egg type, evolve
'Squirtle', 'water', 'None', 'Squirtle Candy', 'Wartortle',
'Wartortle', 'water', 'None', 'Squirtle Candy', 'Blastoise',
'Blastoise', 'water', 'None', 'Squirtle Candy', 'None',
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
