Mori007

insert new database

Feb 24th, 2021
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. # Chalanges insert new data
  2.  
  3. import sqlite3
  4.  
  5.  
  6. # Function to insert data to database
  7. def create(name, cores,  cpu_speed, ram, cost):
  8.     insert_sql = "INSERT INTO computer(name, cores, cpu_speed, ram, cost) VALUES ('{}', {},'{}','{}','{}')".format(name, cores, cpu_speed, ram, cost)
  9.     conn.execute(insert_sql)
  10.     conn.commit()
  11.  
  12. # Making connection to database
  13. conn = sqlite3.connect("d:/Pystrukturdata/databasenya/computer_cards.db")
  14.  
  15. # Making input data
  16. print("Enter the details:")
  17. name = input("Name > ")
  18. cores = input("Cores > ")
  19. cpu_speed = input("CPU Speed > ")
  20. ram = input("Total RAM > ")
  21. cost = input("Cost Computer-$- > ")
  22.  
  23. # Call the function
  24. create(name, cores, cpu_speed, ram, cost)
  25.  
  26. # CLosing connection the database
  27. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment