8000 Update Ch15 exercises by somacdivad · Pull Request #20 · realpython/python-basics-exercises · GitHub
[go: up one dir, main page]

Skip to content

Update Ch15 exercises #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ch15-sql-database-connections/1-use-sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
c = connection.cursor()

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

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

# Exercise 3
# Update the Species of Korben Dallas to "Human"
# Update the Name of Jadzia Dax to "Ezri Dax"
c.execute(
"UPDATE Roster SET Species=? WHERE Name=?", ("Human", "Korben Dallas")
"UPDATE Roster SET Name=? WHERE Name=?", ("Ezri Dax", "Jadzia Dax")
)

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