import sqlite3 db = sqlite3.connect('bookshop.db') result = db.cursor().execute("SELECT * FROM books").fetchall() db.close() my_books =  menu = """Bookshop menu. 1: Choose book 2: View my books 3: Exit >> """ menu_choice = int(input(menu)) while menu_choice != 3: if menu_choice == 1: n = len(result) i = 0 while i < n: print(i, result[i]) #e.g.: 10 The Gruffalo i = i + 1 choice = int(input("Enter book num >> ")) my_books.append(result[choice]) if menu_choice == 2: print(my_books) menu_choice = int(input(menu)).py
n = len(my_books)
my_bookslist in a presentable format, that shoes me all the titles, authors and prices, total price, total credit and credit remaining. It might look like this:
Where's Wally by Martin Hanford. Price: $20.8 The Gruffalo by Donaldson, Julia. Price: $21.95 Total price: $42.75 Total credit: $50 Credit remaining: $7.25
n = len(result)variable (that stores the number of tuples in the books dataset) be calculated at launch of this program (i.e. when i first run the SQL query)? Is there any need for this variable to be recalculated every time I choose choice number 1? Test and discuss.