Skip to content

Commit 358754e

Browse files
authored
Merge pull request #20 from realpython/update-chapter-15-exercises
Update Ch15 exercises
2 parents 6d16c04 + 1a19c41 commit 358754e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

ch15-sql-database-connections/1-use-sqlite.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88
c = connection.cursor()
99

1010
# Exercise 1
11-
# Create a "Roster" table with Name, Species and IQ fields
12-
c.execute("CREATE TABLE Roster(Name TEXT, Species TEXT, IQ INT)")
11+
# Create a "Roster" table with Name, Species and Age fields
12+
c.execute("CREATE TABLE Roster(Name TEXT, Species TEXT, Age INT)")
1313

1414
# Exercise 2
1515
# Add some data into the database
1616
roster_data = (
17-
("Jean-Baptiste Zorg", "Human", 122),
18-
("Korben Dallas", "Meat Popsicle", 100),
19-
("Ak'not", "Mangalore", -5),
17+
("Benjamin Sisko", "Human", 40),
18+
("Jadzia Dax", "Trill", 300),
19+
("Kira Nerys", "Bajoran", 29),
2020
)
2121
c.executemany("INSERT INTO Roster VALUES(?, ?, ?)", roster_data)
2222

2323
# Exercise 3
24-
# Update the Species of Korben Dallas to "Human"
24+
# Update the Name of Jadzia Dax to "Ezri Dax"
2525
c.execute(
26-
"UPDATE Roster SET Species=? WHERE Name=?", ("Human", "Korben Dallas")
26+
"UPDATE Roster SET Name=? WHERE Name=?", ("Ezri Dax", "Jadzia Dax")
2727
)
2828

2929
# Exercise 4
30-
# Display the names and IQs of everyone classified as Human
31-
c.execute("SELECT Name, IQ FROM Roster WHERE Species = 'Human'")
30+
# Display the names and ages of everyone classified as Bajoran
31+
c.execute("SELECT Name, Age FROM Roster WHERE Species = 'Bajoran'")
3232
for row in c.fetchall():
3333
print(row)

0 commit comments

Comments
 (0)