import sqlite3 conn = sqlite3.connect("computer_cards.db") def create(name, cores, cpu_speed, ram, cost): insert_sql = "INSERT INTO computer(name, cores, cpu_speed, ram, cost) VALUES ('{}',{}, {}, {}, {})".format(name, cores, cpu_speed, ram, cost) conn.execute(insert_sql) conn.commit() def read(name): select_sql = "SELECT * FROM computer WHERE name = '{}'".format(name) result = conn.execute(select_sql) return result.fetchone() def update(name): update_sql = "UPDATE computer SET cores = {}, cpu_speed = {}, ram = {}, cost = {} WHERE name = '{}'" conn.execute(update_sql) conn.commit() def delete(name): delete_sql = "DELETE FROM computer WHERE name = '{}'" conn.execute(delete_sql) conn.commit() exitsystem = False while exitsystem == False: command = input("(C)reate, (R)ead, (U)pdate, (D)elete a card or (Q)uit? > ") if command == "C": print("Enter the details to create computer:") name = input("Name > ") cores = input("Cores > ") cpu_speed = input("CPU Speed(GHz) > ") ram = input("RAM(MB) > ") cost = input("Cost($) > ") create(name, cores, cpu_speed, ram, cost) elif command == "R": print("Enter the details to read:") name = input("Name > ") card = read(name) print(card) elif command == "U": print("Enter the computer's details to update computer:") name = input("Name > ") cores = input("Cores > ") cpu_speed = input("CPU Speed(GHz) > ") ram = input("RAM(MB) > ") cost = input("Cost($) > ") update(name, cores, cpu_speed, ram, cost) elif command == "D": print("Enter the computer's details to delete:") name = input("Name > ") confirm = input("Are you sure you want to delete the record for " + name + "? (Y\\N) > " ) if confirm == "Y": print(name, "has been removed from the database.") delete(name) else: print("OK. No records have been deleted.") elif command == "Q": print("Goodbye") exitsystem = True conn.close()