Objective
Create a Python program that modifies an inventory with UPDATE and DELETE, and shows how many rows each operation affects with cursor.rowcount. Use an in-memory database with the sqlite3 module (sqlite3.connect(":memory:")).
Instructions
- Create the table
inventorywithitem(text) andquantity(integer). Readnitems withitem quantityand store them. - Read
moperations. If the line is- item ksubtract that quantity from the item withUPDATE. If it isx itemdelete the item withDELETE. - After each operation show
Affected rows: r(it is 0 if the item does not exist). At the end docommit(). - Show
Inventory:and each item asitem: quantity, sorted by name.
3
tornillo 10
clavo 5
sierra 1
4
- tornillo 3
- lima 2
x sierra
- clavo 5
Affected rows: 1
Affected rows: 0
Affected rows: 1
Affected rows: 1
Inventory:
clavo: 0
tornillo: 7
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise