-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudentmark database connection.py
More file actions
190 lines (165 loc) · 5.12 KB
/
studentmark database connection.py
File metadata and controls
190 lines (165 loc) · 5.12 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import conn
def insert():
a=input("Enter Id: ")
b=input("Enter stName: ")
c=int(input("Tamil: "))
d=int(input("English: "))
e=int(input("Maths: "))
f=int(input("Science: "))
g=int(input("Social: "))
sql="""
insert into Exam (Id, stName, Tamil, English, Maths, Science, Social, Average)
values (%s,%s,%s,%s,%s,%s,%s,(%s+%s+%s+%s+%s)/5)
"""
val=(a,b,c,d,e,f,g,c,d,e,f,g)#cdefg/5 for avg
conn.mycursor.execute(sql, val) //connect to sql file
conn.mydb.commit()
print(conn.mycursor.rowcount,"details inserted")
def select():
print("Id, stName, Tamil, English, Maths, Science, Social, Average:")
query="select Id, stName, Tamil, English, Maths, Science, Social, Average from Exam"
conn.mycursor.execute(query)
myresult=conn.mycursor.fetchall()
for x in myresult:
print(x)
def update_stName():
stName=input("Enter Name: ")
Id=input("Enter Id: ")
sql="update Exam set stName=%s where Id= %s"
conn.mycursor.execute(sql,(stName, Id))
conn.mydb.commit()
print(conn.mycursor.rowcount,"details updated")
def update_Tamil():
Id=input("Enter Id: ")
Tamil=int(input("Tamil Mark: "))
sql="update Exam set Tamil=%s, Average=(Tamil+English+Maths+Science+Social)/5 where Id= %s"
conn.mycursor.execute(sql,(Tamil, Id))
conn.mydb.commit()
print(conn.mycursor.rowcount, "details updated")
def update_English():
Id=input("Enter Id: ")
English=int(input("English Mark: "))
sql="update Exam set English=%s, Average=(Tamil+English+Maths+Science+Social)/5 where Id= %s"
conn.mycursor.execute(sql,(English, Id))
conn.mydb.commit()
print(conn.mycursor.rowcount, "details updated")
def update_Maths():
Id=input("Enter Id: ")
Maths=int(input("Maths Mark: "))
sql="update Exam set Maths=%s, Average=(Tamil+English+Maths+Science+Social)/5 where Id= %s"
conn.mycursor.execute(sql,(Maths, Id))
conn.mydb.commit()
print(conn.mycursor.rowcount, "details updated")
def update_Science():
Id=input("Enter Id: ")
Science=int(input("Science Mark: "))
sql="update Exam set Science= %s, Average=(Tamil+English+Maths+Science+Social)/5 where Id= %s"
conn.mycursor.execute(sql,(Science, Id))
conn.mydb.commit()
print(conn.mycursor.rowcount, "details updated")
def update_Social():
Id=input("Enter Id: ")
Social=int(input("Social Mark: "))
sql="update Exam set Social = %s, Average=(Tamil+English+Maths+Science+Social)/5 where Id = %s"
conn.mycursor.execute(sql,(Social, Id))
conn.mydb.commit()
print(conn.mycursor.rowcount, "details updated")
def update():
print("1. Update stName")
print("2. Update Tamil")
print("3. Update English")
print("4. Update Maths")
print("5. Update Science")
print("6. Update Social")
u=int(input("Select Update subject: "))
if u==1:
update_stName()
elif u==2:
update_Tamil()
elif u==3:
update_English()
elif u==4:
update_Maths()
elif u==5:
update_Science()
elif u==6:
update_Social()
else:
print("Invalid choice")
def delete():
Id=input("Enter Id: ")
query="delete from Exam where Id=%s"
conn.mycursor.execute(query, (Id,))
conn.mydb.commit()
print(conn.mycursor.rowcount, "record(s) deleted")
def Tamil():
query="select Id, stName, Tamil FROM Exam"
conn.mycursor.execute(query)
myresult=conn.mycursor.fetchall()
for x in myresult:
print(x)
def English():
query="select Id, stName, English FROM Exam"
conn.mycursor.execute(query)
myresult=conn.mycursor.fetchall()
for x in myresult:
print(x)
def Maths():
query="select Id, stName, Maths FROM Exam"
conn.mycursor.execute(query)
myresult=conn.mycursor.fetchall()
for x in myresult:
print(x)
def Science():
query="select Id, stName, Science FROM Exam"
conn.mycursor.execute(query)
myresult=conn.mycursor.fetchall()
for x in myresult:
print(x)
def Social():
query="select Id, stName, Social FROM Exam"
conn.mycursor.execute(query)
myresult=conn.mycursor.fetchall()
for x in myresult:
print(x)
def marks():
print("1. Tamil")
print("2. English")
print("3. Maths")
print("4. Science")
print("5. Social")
subject=int(input("Enter your subject: "))
if subject==1:
Tamil()
elif subject==2:
English()
elif subject==3:
Maths()
elif subject==4:
Science()
elif subject==5:
Social()
else:
print("Invalid")
print("1. Insert")
print("2. Select")
print("3. Update")
print("4. Delete")
print("5. Marks")
ch='y'
while ch.lower()=='y':
x=int(input("Enter here: "))
if x==1:
insert()
elif x==2:
select()
elif x==3:
update()
elif x==4:
delete()
elif x==5:
marks()
else:
print("Invalid")
ch=input("Do you want to continue? (y/n): ")
conn.mydb.close()