You are on page 1of 14

KENDRIYA VIDAYALAYA NO

1 SHAHIBAUG AHMEDABAD

Computer Science
Project
Student Management System Using
Python-MySQL Connectivity

By – HARSH MAHORI

12 A
Roll no 12106
Certificate
This is to certify that the project titled ‘Student
Management System Using Python-MySQL Connectivity’ is
prepared by HARSH MAHORI of class 12 A as a Computer
Science project for the academic session 2023-2024 under
the guidance and supervision of Mr. ASHWIN MODI.

Submitted to: Mr. ASHWIN MODI

Signature: ________________
Acknowledgement
I would like to express my gratitude to Mr. ASHWIN MODI for his
able guidance and support in completing this project. He helped
greatly with identifying and fixing my mistakes and without it,
this would have been a difficult task.

I would also like to thank my parents and friends who have


helped me with their valuable suggestions and their guidance,
which has been helpful in various phases of the project and led
to its completion.
The code for the program is as follows-

'''

Table students created in database using the command:

-> create table Students(RollNo int(20) unique, Name varchar(30), Class int(5), House varchar(20),
Percentage float(25));

Sample value for first option of insertion of data:

1, Abhay Kumar, 12, Shivaji, 74.8; 2, Aditi Sharma, 12, Nehru, 87.5; 3, Aditya Kumar, 12, Pratap, 98.3;
4, Aditya Ojha, 12, Nehru, 62.1

'''

import mysql.connector as m

def sel():

curs.execute("select * from Students order by RollNo asc")

print("\n" + "="*80)

for i in curs:

for j in i:
print(j, end = "\t|\t")

print("\n" + "="*80)

conn = m.connect(host = "localhost", user = 'root', passwd = '1234', database = 'practical')

curs = conn.cursor()

loop = 0

while loop == 0:

loop2 = 0

while loop2 == 0:

try:

inp = int(input("\nWhat would you like to do?\n 1. Insert\n 2. Delete\n 3. Update\n 4. Search\n 5.
Display all\n 6. Exit\n\n"))

loop2 = 1

except:

continue

if inp == 1:

ins = "insert into Students values(%s, %s, %s, %s, %s)"

a = tuple(input("\nPlease enter values you would like to add to the table:\n(R.No, Name, Class,
House, %age)\n").split("; "))

for i in a:

b = tuple(i.split(", "))

try:
curs.execute(ins, b)

except:

print("There's already an entry with that roll number. Please try again.")

else:

sel()

elif inp == 2:

b = int(input("\nWhich entry would you like to delete?\n Roll No: "))

de = "delete from Students where RollNo={}".format(b)

curs.execute(de)

sel()

elif inp == 3:

dest = int(input("\nWhich entry do you want to update?\n Roll No: "))

c = int(input("\nWhich detail do you want to update?\n 1. Roll No\n 2. Name\n 3. Class\n 4.


House\n 5. Percentage\n"))

if c == 1:

ch = input("\nEnter the new roll no: ")

u = "update Students set RollNo={} where RollNo={}".format(ch, dest)

try:

curs.execute(u)

except:
print("There's already an entry with that roll number. Please restart and try again.")

else:

sel()

elif c == 2:

u = "update Students set Name=(%s) where RollNo=(%s)"

ch = input("\nEnter the new name: ")

tog = (ch, dest)

curs.execute(u, tog)

sel()

elif c == 3:

ch = input("\nEnter the new class: ")

u = "update Students set Class={} where RollNo={}".format(ch, dest)

curs.execute(u)

sel()

elif c == 4:

u = "update Students set House=(%s) where RollNo=(%s)"

ch = input("\nEnter the new house: ")

tog = (ch, dest)

curs.execute(u, tog)
sel()

elif c == 5:

ch = input("\nEnter the new percentage: ")

u = "update Students set Percentage={} where RollNo={}".format(ch, dest)

curs.execute(u)

sel()

elif inp == 4:

curs.execute("select RollNo from Students")

rno = []

for a in curs:

for b in a:

rno.append(b)

d = int(input("\nEnter roll no: "))

s = "select * from Students where RollNo={}".format(d)

curs.execute(s)

if d in rno:

for i in curs:
print("\n" + "="*80)

for j in i:

print(j, end = "\t|\t")

print("\n" + "="*80 + "\n")

else: print("There are no matching entries.")

elif inp == 5:

sel()

elif inp == 6:

loop = 1

conn.commit()
The output for the given code is as follows-
What would you like to do?

1. Insert

2. Delete

3. Update

4. Search

5. Display all

6. Exit

Input- 1
Please enter values you would like to add to the table:

(R.No, Name, Class, House, %age)

1, Abhay Kumar, 12, Shivaji, 74.8; 2, Aditi Sharma, 12, Nehru, 87.5; 3, Aditya Kumar, 12, Pratap,
98.3; 4, Aditya Ojha, 12, Nehru, 62.1

============================================================

1 | Abhay Kumar | 12 | Shivaji | 74.8 |

============================================================

2 | Aditi Sharma | 12 | Nehru | 87.5 |

============================================================

3 | Aditya Kumar | 12 | Pratap | 98.3 |

============================================================

4 | Aditya Ojha | 12 | Nehru | 62.1 |

============================================================
Input- 2
Which entry would you like to delete?

Roll No: 3

============================================================

1 | Abhay Kumar | 12 | Shivaji | 74.8 |

============================================================

2 | Aditi Sharma | 12 | Nehru | 87.5 |

============================================================

4 | Aditya Ojha | 12 | Nehru | 62.1 |

============================================================

Input= 3
Which entry do you want to update?

Roll No: 4

Which detail do you want to update?

1. Roll No

2. Name

3. Class

4. House

5. Percentage

1
Enter the new roll no: 3

============================================================

1 | Abhay Kumar | 12 | Shivaji | 74.8 |

=============================================================

2 | Aditi Sharma | 12 | Nehru | 87.5 |

=============================================================

3 | Aditya Ojha | 12 | Nehru | 62.1 |

=============================================================

Input= 4
Enter roll no: 3

============================================================

3 | Aditya Kumar | 12 | Pratap | 98.3 |

============================================================
Input= 5
============================================================

1 | Abhay Kumar | 12 | Shivaji | 74.8 |

============================================================

2 | Aditi Sharma | 12 | Nehru | 87.5 |

============================================================

3 | Aditya Kumar | 12 | Pratap | 98.3 |

============================================================

4 | Aditya Ojha | 12 | Nehru | 62.1 |

============================================================

Input= 6
The code for ‘elif inp==6’ exits the program by breaking the loop of asking the user what they
would like to do and saving the changes using ‘conn.commit()’.

You might also like