-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-sql.py
52 lines (42 loc) · 1.62 KB
/
python-sql.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
"""
Dummy Project that will display the total marks obtained by students in different
subjects based on the selections made
in the console"""
#import the required libraries
import sqlite3
"""
Writing the program as Class-object model
"""
class SQLConnector:
def __init__(self,database,con=0):
self.con = sqlite3.connect(database)
def apply_logic(self,num):
cur = self.con.cursor()
cur.execute("SELECT sum(marks) FROM students WHERE subject ='Chemistry'")
chem_marks = cur.fetchall()
cur.execute("SELECT sum(marks) FROM students WHERE subject ='Physics'")
phy_marks = cur.fetchall()
cur.execute("SELECT sum(marks) FROM students WHERE subject ='Biology'")
bio_marks = cur.fetchall()
switcher ={
1:chem_marks,
2:phy_marks,
3:bio_marks
}
result = switcher.get(num,'-1')
if result is not '-1':
for i in result:
for j in range(len(i)):
return result[j][0]
else:
return "Invalid Operation"
self.con.commit()
self.con.close()
if __name__=="__main__":
print("Select any number below in order to run the required condition")
print("Type 1 to display the total marks scored by Students in Chemistry")
print("Type 2 to display the total marks scored by Students in Physics")
print("Type 3 to display the total marks scored by Students in Biology")
n = int(input())
sql = SQLConnector("python-sql.db")
print(sql.apply_logic(n))