-
-
Save parzibyte/871e680bf2d945a5b0f7cfcc3180925a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
try: | |
bd = sqlite3.connect("libros.db") | |
cursor = bd.cursor() | |
busqueda = input("Escribe tu búsqueda: ") | |
if not busqueda: | |
print("Búsqueda inválida") | |
exit() | |
sentencia = "SELECT * FROM libros WHERE titulo LIKE ?;" | |
cursor.execute(sentencia, [ "%{}%".format(busqueda) ]) | |
libros = cursor.fetchall() | |
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+".format("", "", "", "")) | |
print("|{:^20}|{:^20}|{:^10}|{:^50}|".format("Autor", "Género", "Precio", "Título")) | |
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+".format("", "", "", "")) | |
for autor, genero, precio, titulo in libros: | |
print("|{:^20}|{:^20}|{:^10}|{:^50}|".format(autor, genero, precio, titulo)) | |
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+".format("", "", "", "")) | |
except sqlite3.OperationalError as error: | |
print("Error al abrir:", error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment