8000 Merge pull request #12 from topleft/chap13 · coderwxy/book1-exercises@07d4a90 · GitHub
[go: up one dir, main page]

Skip to content

Commit 07d4a90

Browse files
committed
Merge pull request realpython#12 from topleft/chap13
reviewed and changed file/dir names
2 parents 878c13f + 5e0287c commit 07d4a90

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

refactor/chp13/solutions/13-1.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 13.1 review exercises
2+
3+
import sqlite3
4+
5+
# Create a temporary database connection in RAM
6+
with sqlite3.connect(':memory:') as connection:
7+
c = connection.cursor()
8+
9+
# Create a "Roster" table with Name, Species and IQ fields
10+
c.execute("CREATE TABLE Roster(Name TEXT, Species TEXT, IQ INT)")
11+
12+
# Add some data into the database
13+
roster_data = (
14+
("Jean-Baptiste Zorg", "Human", 122),
15+
("Korben Dallas", "Meat Popsicle", 100),
16+
("Ak'not", "Mangalore", -5)
17+
)
18+
c.executemany("INSERT INTO Roster VALUES(?, ?, ?)", roster_data)
19+
20+
# Update the Species of Korben Dallas to "Human"
21+
c.execute("UPDATE Roster SET Species=? WHERE Name=?",
22+
('Human', 'Korben Dallas'))
23+
24+
# Display the names and IQs of everyone classified as Human
25+
c.execute("SELECT Name, IQ FROM Roster WHERE Species = 'Human'")
26+
for row in c.fetchall():
27+
print(row)

0 commit comments

Comments
 (0)
0