From e8ead086b5691deefb0b8eb144a4794beecb8a4e Mon Sep 17 00:00:00 2001 From: qaidjoharj53 Date: Wed, 3 May 2023 22:29:22 +0530 Subject: [PATCH] student mngmnt sys upload --- CS_Source Code.py | 197 ++++++++++++++++++++++++++++++++++++++++++++++ stud.dat | Bin 0 -> 441 bytes 2 files changed, 197 insertions(+) create mode 100644 CS_Source Code.py create mode 100644 stud.dat diff --git a/CS_Source Code.py b/CS_Source Code.py new file mode 100644 index 0000000..d2dd326 --- /dev/null +++ b/CS_Source Code.py @@ -0,0 +1,197 @@ +"""to maintain student details +roll number +name +percentage +""" +""" +modules imported +""" +import pickle +import os +import time +""" +class used +""" +class student(object): + def __int__(s): + s.roll=0 + s.name="" + s.per=0 + def add_rec(s): + s.roll=int(input("Enter roll number: ")) + s.name=input("Enter name: ") + s.name=s.name.upper() + s.per=float(input("Enter percentage: ")) + def disp_rec(s): + print("roll number: ",s.roll) + print("name: ",s.name) + print("percentage: ",s.per) + def display_rec(s): + print("%-10s"%s.roll,"%-20s"%s.name,"%-10s"%s.per) + #print("in display_rec") + def modify_rec(s): + s.roll=int(input("Enter new roll number: ")) + s.name=input("Enter new name: ") + s.name=s.name.upper() + s.per=float(input("Enter new percentage: ")) +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 continue....") + except: + pass +def display_all(): + print(40*"=") + print("\n\t Student Records\n") + print(40*"=") + try: + file=open("stud.dat","rb") + while True: + rec=pickle.load(file) + rec.display_rec() + except EOFError: + file.close() + print(40*"=") + input("Press any key to continue....") + except IOError: + print("File could not be opened!!") +def search_roll(): + try: + z=0 + print(40*"=") + print("Record searching by roll number...") + print(40*"=") + n=int(input("Enter roll number to 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 continue....") +def search_name(): + try: + z=0 + print(40*"=") + print("Record searching by name...") + print(40*"=") + 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 + 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 continue....") +def modify_roll(): + z=0 + try: + n=int(input("Enter roll number 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("\nRecord found and details are:\n") + rec.disp_rec() + print("\nEnter 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 continue....") +def delete_roll(): + z=0 + try: + n=int(input("Enter roll number 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("\nRecord to delete found and details are:\n") + 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 continue....") +while True: + os.system("cls") + print(40*"=") + print(""" Main Menu + --------- + 1. Add record + 2. Display all records + 3. Search by roll number + 4. Search by name + 5. Modify by roll number + 6. Delete by roll number + 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("\n\t !!!End!!!\n") + time.sleep(2) + break + else: + print("Invalid choice!!") + time.sleep(1) diff --git a/stud.dat b/stud.dat new file mode 100644 index 0000000000000000000000000000000000000000..1fe08aaff338fc9142d9730491ec40e8e9aff3c1 GIT binary patch literal 441 zcmZo*nd-v;0X-b?@wthadGYa6df1CgN>ftvN~TPnqS-j5c8W$1OHqDK&J^#|9+tes z+|(&OT#kO8J__!k0U?f4dYB7Ri>A0cgf)OoDoxUBV43Piim_=hV|ju-9D^KP6ukU{ zJv`wCha5mMm?Zb6!wlwf^zsZ*@DBBL41yaQ0dXQ3?#+N1%M;}2?HcT%5bWvafe46T dWcQL35Seg;!#ur%9DP9syL-T09PR)M2msT_kT3uM literal 0 HcmV?d00001