|
8 | 8 | c = connection.cursor()
|
9 | 9 |
|
10 | 10 | # 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)") |
13 | 13 |
|
14 | 14 | # Exercise 2
|
15 | 15 | # Add some data into the database
|
16 | 16 | 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), |
20 | 20 | )
|
21 | 21 | c.executemany("INSERT INTO Roster VALUES(?, ?, ?)", roster_data)
|
22 | 22 |
|
23 | 23 | # Exercise 3
|
24 |
| - # Update the Species of Korben Dallas to "Human" |
| 24 | + # Update the Name of Jadzia Dax to "Ezri Dax" |
25 | 25 | c.execute(
|
26 |
| - "UPDATE Roster SET Species=? WHERE Name=?", ("Human", "Korben Dallas") |
| 26 | + "UPDATE Roster SET Name=? WHERE Name=?", ("Ezri Dax", "Jadzia Dax") |
27 | 27 | )
|
28 | 28 |
|
29 | 29 | # 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'") |
32 | 32 | for row in c.fetchall():
|
33 | 33 | print(row)
|
0 commit comments