BestPromptFinderBelow is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: Write a Python program to generate an HTML table displaying information about the top 10 bestselling books in a specific genre. ### Input: Table name: Books Table columns: id (int), title (string), author (string), genre (string), sales (int) ### Output: import sqlite3 # connect to the database conn = sqlite3.connect('books.db') c = conn.cursor() # retrieve the data c.execute('''SELECT title, author, genre, sales FROM Books WHERE genre='Fantasy' ORDER BY sales DESC LIMIT 10''') # save the results results = c.fetchall() # generate the HTML code html = ' ' html += ' Title Author Genre Sales ' for result in results: title = result[0] author = result[1] genre = result[2] sales = result[3] html += f' {title} {author} {genre} {sales} ' html += ' ' # display the results print(html)
Find similar in the app →