Advertisement
teslariu

ejemplo para administrar tablas

Oct 4th, 2022 (edited)
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Script para administrar una base
  5. import sqlite3
  6.  
  7. conn = sqlite3.connect("productos.db")
  8. cursor = conn.cursor()
  9.  
  10. def menu():
  11.     return f"""
  12.    Menu de administración de ....
  13.    ------------------------------
  14.        1. Agregar registro
  15.        2. Ver registros
  16.        3. Borrar registros
  17.        4. Modificar registros
  18.        5. Salir
  19.    ------------------------------
  20.    """
  21.  
  22. while True:
  23.     print(menu())
  24.     opcion = input("Seleccione su opción: ")
  25.    
  26.     if opcion == "1":
  27.         nombre = input("Nombre: ")
  28.         edad = int(input("Edad: "))
  29.         cursor.execute("INSERT INTO Personas VALUES(?,?)",(nombre, edad))
  30.         conn.commit()
  31.    
  32.     elif opcion == "2":
  33.         pass
  34.    
  35.     elif opcion == "3":
  36.         pass
  37.        
  38.     elif opcion == "4":
  39.         pass
  40.    
  41.     elif opcion == "4":
  42.         print("Cerrando conexiòn con la base...")
  43.         conn.close()
  44.         break
  45.        
  46.     else:
  47.         print("Opción incorrecta...")
  48.        
  49.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement