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 sqlite3 database using Python. We will
use a database of Pokemon as an example.
Use the following codes as the basis for this exercise.
import sqlite3
# create connection and cursor
conn = sqlite3.connect ('pokemon.db')
cursor = conn. cursor ()
# execute SQL query. In this example, show all data in [pokemon_meta] table
cursor.execute("SELECT * from [pokemon_meta]")
rows=cursor. fetchall()
# print the column names of the table
header =
for column_info in cursor.description:
header+=column_info[",
print (header)
#print the table content
for row in rows:
print(row)
#close connection after using it
conn.close()
In the sample codes, cursor.description provides the column names of the last query
(cursor.execute("SELECT* from [pokemon_meta]") 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
column_info in the first for-loop, column_info refers to the tuples in the list one by one, and
column_info[0] refers to the name of a column
The program above reads from a table named [pokemon_meta], and show all the content of
the table.
Task 2
Currently, the table did not reflect the fact that Squirtle can evolve into Wartortle, and
Wartotle evolve into Blastoise
(2 points) Extend the program, so that it updates the [pokemon_meta] table, so that the
[evolve_into] 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 [pokemon_meta] set [evolve_to]='Wartortle' WHERE
[name]=' Squirtle' '
Don't forget to commit the changes
(1 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):
pokedexID, name, type1,type2,baseweight, base height, catch chance, base cp, candy type, egg type, evolve to
(7, 'Squirtle', 'water', 'None', 9.0,0.5,0.9,32, 'Squirtle Candy', 5, 'Wartortle', 25)
(8, 'Wartortle', 'water', 'None', 22.5,1.0,0.8,40, 'Squirtle Candy', , 'Blastoise', 100)
(9, 'Blastoise', 'water', 'None', 85.5,1.6,0.3,53, 'Squirtle Candy', 0, 'None', -1)
 In this assignment, you'll practice accessing data in sqlite3 database using

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!