0% found this document useful (0 votes)
1K views4 pages

Student Management System (Python Code)

This Python program is a student management system that allows users to insert, view, update, and delete student records from a database table. The program displays a menu where the user can select an option to perform the desired CRUD operation. Based on the choice, it connects to a MySQL database and executes the corresponding SQL query to manipulate the student data in the table.

Uploaded by

Om Tank
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
1K views4 pages

Student Management System (Python Code)

This Python program is a student management system that allows users to insert, view, update, and delete student records from a database table. The program displays a menu where the user can select an option to perform the desired CRUD operation. Based on the choice, it connects to a MySQL database and executes the corresponding SQL query to manipulate the student data in the table.

Uploaded by

Om Tank
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

Python Project – Student Management System

import pymysql
import os
exit='n'
while exit=='n':
    os.system('cls')
    print('-' * 90)
    print('|'+' '*31+'STUDENT MANAGEMENT SYSTEM'+' ' * 32+ '|')
    print('-' * 90)
    print('| [I]nsert Record |', end='')
    print('  [V]iew Record   |', end='')
    print('  [U]pdate Record |',end='')
    print('  [D]elete Record |',end='')
    print('    [E]XIT   |')
    print('-' * 90)
    ch=input('YOUR Choice (I/V/U/D/E):')
    ch = ch.upper()
    if ch == 'I':
       
        connection=pymysql.connect(host="localhost", user="root", pass
wd="root", db="school")
        mycursor=connection.cursor()
        choice='y'
        while choice=='y':
        
            sno=input('enter the roll number of student ')
            sname=input('enter the name of student ')
            Qry = ("INSERT INTO class12 "\
                   "VALUES (%s, %s)") 
            data = (sno,sname) 
            mycursor.execute(Qry,data) 
            print('RECORD INSERTED SUCCESSFULLY')
            choice=input('do you with to insert more records (y/n)')
            if choice=='y':
                continue
            connection.commit()
            connection.close()
    elif ch == 'V':

www.anjeevsinghacademy.com
Python Project – Student Management System
        
        connection=pymysql.connect(host="localhost", user="root", pass
wd="root", db="school")
        mycursor=connection.cursor()
        #mycursor.execute("""create table class12 (rno int, name varch
ar(20))""")
        choice='y'
        while choice=='y':
        
            rno=int(input('enter the roll number of student whose reco
rd you want to search '))

            Qry = ("""select * from class12 WHERE rno = %s""") 
            data = (rno,) 
            mycursor.execute(Qry,data) 

            count=0
            for(rno,name)in mycursor:
                count+=1
                print('===========')
                print('Student Roll No  ',rno)
                print('Student Name     ',name)
                print('===========')
                if count%2==0:
                    print('press any key to continue')
                    clrscreen()
                print('total records',count,'found')
        
            choice=input('do you with to search more record(y/n)')
            if choice=='y':
                continue

            connection.commit()
            connection.close()
    elif ch == 'U':
        

www.anjeevsinghacademy.com
Python Project – Student Management System
        connection=pymysql.connect(host="localhost", user="root", pass
wd="root", db="school")
        mycursor=connection.cursor()
        #mycursor.execute("""create table class12 (rno int, name varch
ar(20))""")
        choice='y'
        while(choice=='y'):
        
            rno=int(input('enter the roll number of student whose reco
rd you want to change '))
            name=input('enter new name')

            Qry = ("""UPDATE class12 set name=%s WHERE rno = %s""") 
            data = (name,rno) 
            mycursor.execute(Qry,data) 
            print('RECORD UPDATED SUCCESSFULLY')
        
            choice=input('do you wish to update more records(y/n)')
            if choice=='y':
                continue
            connection.commit()
            connection.close()
    elif ch == 'D':
        
        connection=pymysql.connect(host="localhost", user="root", pass
wd="root", db="school")
        mycursor=connection.cursor()
        #mycursor.execute("""create table class12 (rno int, name varch
ar(20))""")
        choice='y'
        while choice=='y':
        
            rno=int(input('enter the roll number of student whose reco
rd you want to delete '))

            Qry = ("""DELETE FROM class12 WHERE rno = %s""") 
            data = (rno,) 

www.anjeevsinghacademy.com
Python Project – Student Management System
            mycursor.execute(Qry,data) 
            print('RECORD DELETED SUCCESSFULLY')
            choice=input('Do you wish to delete more records(y/n) ?')
            if choice=='y':
                continue
            connection.commit()
            connection.close()
    elif ch == 'E':
        print("\n\t\t Thanks for using Student Management System...")
        print("\t\t-------------------------------------------")
        print("\t\t|   Created By - anjeevsinghacademy.com   |")
        print("\t\t-------------------------------------------")
        break
    else:
        print('\t\t\t Error : Not a Valid Option ')
        print('\t\t Valid option are "I", "V", "U", "D", or "E" only')
        exit=input('\t\t Do you wish to exit the program(y/n)')
        if exit=='n':
            continue

www.anjeevsinghacademy.com

You might also like