input: Write a function to generate an HTML table displaying information about the top 10 bestselling books in a specific genre by querying a SQLite database. The function should accept the genre name as a parameter and return the generated HTML code.
  
  def generate_bestseller_table(genre):
   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=?
   ORDER BY sales DESC
   LIMIT 10''', (genre,))
  
   # save the results
   results = c.fetchall()
  
   # generate the HTML code
   html = '<table>'
   html += '<tr><th>Title</th><th>Author</th><th>Genre</th><th>Sales</th></tr>'
  
   for result in results:
    title = result[0]
    author = result[1]
    genre = result[2]
    sales = result[3]
  
    html += f'<tr><td>{title}</td><td>{author}</td><td>{genre}</td><td>{sales}</td></tr>'
  
   html += '</table>'
  
   # close the connection
   conn.close()
  
   return html
  
  assert generate_bestseller_table('Fantasy').startswith('<table>')
  assert generate_bestseller_table('Mystery').find('<tr><th>Title</th>') != -1
  assert generate_bestseller_table('Science Fiction').endswith('</table>')
  assert generate_bestseller_table('Romance').count('<tr>') > 3
output: def generate_bestseller_table(genre):
   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=?
   ORDER BY sales DESC
   LIMIT 10''', (genre,))
  
   # save the results
   results = c.fetchall()
  
   # generate the HTML code
   html = '<table>'
   html += '<tr><th>Title</th><th>Author</th><th>Genre</th><th>Sales</th></tr>'
  
   for result in results:
    title = result[0]
    author = result[1]
    genre = result[2]
    sales = result[3]
  
    html += f'<tr><td>{title}</td><td>{author}</td><td>{genre}</td><td>{sales}</td></tr>'
  
   html += '</table>'
  
   # close the connection
   conn.close()
  
   return html