0% found this document useful (0 votes)
4 views9 pages

Binary Program

The document contains Python code for managing student records using the pickle module, allowing for insertion, display, updating, searching, and deletion of records. It includes functions to handle data in a binary file format, ensuring data persistence. Error handling is implemented to manage end-of-file conditions during file operations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Binary Program

The document contains Python code for managing student records using the pickle module, allowing for insertion, display, updating, searching, and deletion of records. It includes functions to handle data in a binary file format, ensuring data persistence. Error handling is implemented to manage end-of-file conditions during file operations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import pickle

def insert():
f = open("[Link]", "ab")
roll = int(input("Enter Roll Number: "))
name = input("Enter Name: ")
marks = int(input("Enter Marks: "))
student = [roll, name, marks]
[Link](student, f)
[Link]()
print("Record Inserted Successfully")
insert()
import pickle
def display():
f = open("[Link]", "rb")

try:
while True:
student = [Link](f)

print("Roll Number :", student[0])


print("Name :", student[1])
print("Marks :", student[2])
print("----------------------")
except EOFError:
[Link]()
display()
def update():
f = open("[Link]", "rb")
temp = open("[Link]", "wb") except EOFError:
pass
r = int(input("Enter Roll Number to Update: "))

found = False [Link]()


[Link]()
try:
while True: [Link]("[Link]")
student = [Link](f)
[Link]("[Link]", "[Link]")
if student[0] == r:
print("Current Details") if found:
print(student) print("Record Updated Successfully")
else:
student[1] = input("Enter New Name: ") print("Record Not Found")
student[2] = int(input("Enter New Marks: "))

found = True

[Link](student, temp)
def search():
f = open("[Link]", "rb")
r = int(input("Enter Roll Number to Search: "))
found = False

try:
while True:
student = [Link](f)

if student[0] == r:
print("Record Found")
print("Roll Number :", student[0])
print("Name :", student[1])
print("Marks :", student[2])

found = True
break

except EOFError:
if found == False:
print("Record Not Found")
[Link]()
import pickle import pickle

def insert(): def insert():


f = open("[Link]", "ab")
f = open("[Link]",'ab')
roll = int(input("Enter Roll Number: "))
name = input("Enter Name: ") rno = int(input("Enter a number: "))
marks = int(input("Enter Marks: "))
student = [roll, name, marks] name = input("Enter a name: ")

[Link](student, f) stu = {'Rollno': rno, 'Name': name}

[Link]() [Link](stu, f)
[Link]()
print("Record Inserted Successfully")
print("Record added successfully")
def display(): import pickle
f = open("[Link]", "rb")
def display():
try:
while True: f = open("[Link]",'rb')
student = [Link](f)
try:
print("Roll Number :", student[0]) while True:
print("Name :", student[1])
print("Marks :", student[2]) r = [Link](f)
print("----------------------")
print(r)
except EOFError:
[Link]() except EOFError:
[Link]()

display()
import pickle
import os except EOFError:
pass
def update():
f = open("[Link]", "rb") finally:
[Link]()
r = int(input("Enter Roll Number to update: ")) temp_file.close()

temp_file = open("[Link]", "wb") [Link]("[Link]")


[Link]("[Link]", "[Link]")
try:
while True: update()
student = [Link](f)

if student["Rollno"] == r:
print("Current Details:")
print("Roll Number:", student["Rollno"])
print("Name:", student["Name"])
name = input("Enter the New Name: ")
student["Name"] = name
print("Student details updated successfully.")

[Link](student, temp_file)
import pickle
finally:
import os [Link]()
def delete(): temp_file.close()
[Link]("[Link]")
f=open("[Link]", "rb")
[Link]("[Link]", "[Link]")
r=int(input("Enter The Roll Number to be deleted: ")) print("Student deleted successfully.")
temp_file=open("[Link]", "wb")
delet
try:
while True:
student= [Link](f)
if student["Roll No"] != r:
[Link] (student, temp_file)
except EOFError:
pass
import pickle

def search():
f = open("[Link]", 'rb')
r = int(input("Enter roll number to search: "))
found = False
try:
while True:
stu = [Link](f)
if stu['Rollno'] == r:
print("Record Found:")
print("Rollno:", stu['Rollno'])
print("Name:", stu['Name'])
found = True
break
except EOFError:
pass

if not found:
print("Record not found")

[Link]()

You might also like