Error proofing
error_proofing.py
import sqlite3
db = sqlite3.connect('bookshop.db')
result = db.cursor().execute("SELECT * FROM books").fetchall()
db.close()
n = len(result)
i = 0
while i < n:
print(i, result[i][1]) #e.g.: 10 The Gruffalo
i = i + 1
while True:
try:
choice = int(input("Enter book num >> "))
print("Your book choice: ", result[choice])
break
except:
print("Invalid book num. Try again.")