-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreating_cards_database.py
67 lines (42 loc) · 1.49 KB
/
creating_cards_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sqlite3
conn = sqlite3.connect("computer_cards.db")
def create(name, cores):
insert_sql = "INSERT INTO computer(name, cores, cpu_speed, ram, cost) VALUES ('{}', {}, {}, {}, {})".format(name, cores)
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, cores, cpu_speed, ram, cost):
update_sql = "UPDATE computer SET cores = {}, cpu_speed = {}, ram = {}, cost = {} WHERE name = '{}'".format(cores, cpu_speed, ram, cost, name)
conn.execute(update_sql)
conn.commit()
def delete(name):
delete_sql = "DELETE FROM computer WHERE name = '{}'".format(name)
conn.execute(delete_sql)
conn.commit()
print("Enter the details:")
command = input("(C)reate (R)ead, (U)pdate, (D)elete card > ")
if command == "C":
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":
name = input("Name >")
card = read(name)
print(card)
elif command == "U":
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":
name = input("Name >")
delete(name)
conn.close()