CLASS 12 PYTHON PROJECT

Python Student Database Management System 2

This project maintains student details like:

rollno
name
m1
m2
m3
total
per

This project will clear the basic concepts of project development for student. Using this project as base the fields can be changed and a large project can be developed.

This project uses binary file handling to store and maintain the student data.

Here we have options for

  • Adding a new record in the binary file
  • Display all the records from the file
  • Search a record on the basis of roll no
  • Searh a record on the basis of name
  • Modify a record on the basis of roll no
  • Delete a record by roll no

Screen Shots of the above project

Main Menu

Python Project : Student2 : rajeshshuklacatalyst.in

 

Display All The Records

 

Python Project : Student2 : rajeshshuklacatalyst.in

 

Search Record By Roll No

 

Python Project : Student2 : rajeshshuklacatalyst.in

 

Search Record By Name

 

Python Project : Student2 : rajeshshuklacatalyst.in

View the  Project

student2.py

Download Project

"""to maintain student details
roll
name
m1
m2
m3
total
per
"""
"""
modules imported

"""
import pickle
import os

"""
class used
"""

class student(object):
    def __int__(s):
        s.roll=0
        s.name=""
        s.m1=0
        s.m2=0
        s.m3=0
        s.total=0
        s.per=0

    def add_rec(s):
        s.roll=int(input("Enter roll no "))
        s.name=input("Enter name ")
        s.name=s.name.upper()
        s.m1=float(input("Enter marks of m1 "))
        s.m2=float(input("Enter marks of m2 "))
        s.m3=float(input("Enter marks of m3 "))
        s.total=s.m1+s.m2+s.m3
        s.per=s.total/3
        
    def disp_rec(s):
        print("roll ",s.roll)
        print("name ",s.name)
        print("m1 ",s.m1)
        print("m1 ",s.m2)
        print("m1 ",s.m3)
        print("m1 ",s.total)
        print("per ",s.per)

    def display_rec(s):
        print("%-10s"%s.roll,"%-20s"%s.name,"%-10s"%s.m1,"%-10s"%s.m2,"%-10s"%s.m3,"%-10s"%s.total,"%-10s"%s.per)
        #print("in display_rec")
        
    def modify_rec(s):
        s.roll=int(input("Enter new roll no "))
        s.name=input("Enter new name ")
        s.name=s.name.upper()
        s.m1=float(input("Enter marks of m1 "))
        s.m2=float(input("Enter marks of m2 "))
        s.m3=float(input("Enter marks of m3 "))
        s.total=s.m1+s.m2+s.m3
        s.per=s.total/3
    


def write_record():
    try:
        rec=student()
        file=open("stud.dat","ab")
        rec.add_rec()
        pickle.dump(rec,file)
        file.close()
        print("Record added in file")
        input("Press any key to cont ....")
    except:
        pass


def display_all():
    os.system("cls")
    print(80*"=")
    print("\n             Student Records\n")
    print(80*"=")
    print("\n");
    print("Roll No      Name                 m1         m2        m3       Total       Per\n");
    print(80*"=")
    try:
        file=open("stud.dat","rb")
        while True:
            rec=pickle.load(file)
            rec.display_rec()
            
            
    except EOFError:
        file.close()
        print(80*"=")
        input("Press any key to cont ....")
    except IOError:
        print("file could not be opened")
        
def search_roll():
    os.system("cls")
    try:
        z=0
        print(40*"=")
        print("Record Searching By Roll No")
        print(40*"=")
        n=int(input("Enter roll no search "))
        file=open("stud.dat","rb")
        while True:
            rec=pickle.load(file)
            #print(rec.roll)
            if(rec.roll==n):
                z=1
                print("\nRecord Found and details are\n")
                rec.disp_rec()
                break
    except EOFError:
        file.close()
        if(z==0):
            print("record is not present")
        
    except IOError:
        print("file could not be opened")
    input("Press any key to cont ....")
        
def search_name():
    os.system("cls")
    try:
        z=0
        n=input("Enter name to search ")
        file=open("stud.dat","rb")
        while True:
            rec=pickle.load(file)
            #print(rec.roll)
            if(rec.name==n.upper()):
                z=1
                rec.disp_rec()
                break
    except EOFError:
        file.close()
        if(z==0):
            print("record is not present")
        
    except IOError:
        print("file could not be opened")   
    input("Press any key to cont ....")    

def modify_roll():
    os.system("cls")
    z=0
    try:
        n=int(input("Enter roll no to modify "))
        file=open("stud.dat","rb")
        temp=open("temp.dat","wb")
        while True:
            rec=pickle.load(file)
            if(rec.roll==n):
                z=1
                print("record found and details are")
                rec.disp_rec()
                print("Enter new data ")
                rec.modify_rec()
                pickle.dump(rec,temp)
                print("Record updated")
            else:
                pickle.dump(rec,temp)

    except EOFError:
        file.close()
        temp.close()
        if(z==0):
            print("Record not found")
    except IOError:
        print("File could not be opened")

    os.remove("stud.dat")
    os.rename("temp.dat","stud.dat")
    input("Press any key to cont ....")

def delete_roll():
    os.system("cls")
    z=0
    try:
        n=int(input("Enter roll no to delete "))
        file=open("stud.dat","rb")
        temp=open("temp.dat","wb")
        while True:
            rec=pickle.load(file)
            if(rec.roll==n):
                z=1
                print("record to delete found and details are")
                rec.disp_rec()
                #pickle.dump(rec,temp)
                #print("Record updated")
            else:
                pickle.dump(rec,temp)

    except EOFError:
        file.close()
        temp.close()
        if(z==0):
            print("Record not found")
    except IOError:
        print("File could not be opened")

    os.remove("stud.dat")
    os.rename("temp.dat","stud.dat")
    input("Press any key to cont ....")



while True:
    os.system("cls")
    print(40*"=")
    print("""            Main Menu
            ---------

           1. Add recod
           2. display all records
           3. search by rollno
           4. search by name
           5. Modify by rollno
           6. delete by rollno
           7. exit
    """)
    print(40*"=")
    ch=int(input("Enter your choice "))
    print(40*"=")
    if(ch==1):
        write_record()
    elif(ch==2):
        display_all()
    elif(ch==3):
        search_roll()
    elif(ch==4):
        search_name()
    elif(ch==5):
        modify_roll()
    elif(ch==6):
        delete_roll()
    elif(ch==7):
        print("End")
        break
    else:
        print("Invalid choice")

    
          
    
        

Download Project and Output in word format

CBSE Class 12 @ Python

  • Home Page class 12 @ Python
  • Class 12 @ Python Theory Syllabus
  • Class 12 @ Python Practical Syllabus
  • Revision Tour
  • Functions (Funcations, Inbuilt Functions, Python Modules, Python Packages)
  • Inbuilt Functions
  • Python Modules
  • Python Packages
  • Using Python Libraries
  • Python Data File Handling
  • Program Efficiency
  • Data Structures In Python
  • Data Visualization Using Pyplot
  • Computer Networks
  • MySQL
  • Interface Python with SQL
  • Society, Law and Ethics
  • Web Development with Django
  • Class 12 @ Python Sample Practical File
  • Class 12 @ Python Sample Papers
  • Class 12 @ Python Projects
  • Tutorials

    Technical Questions

    Interview Questions

    C Programming
    C++ Programming
    Class 11 (Python)
    Class 12 (Python)
    C Language
    C++ Programming
    Python

    C Interview Questions
    C++ Interview Questions
    C Programs
    C++ Programs