import pickle
def add_record():
roll = int(input("Enter Roll Number: "))
name = input("Enter Name: ")
with open("[Link]", "ab") as file:
[Link]([roll, name], file)
def display_records():
try:
with open("[Link]", "rb") as file:
while True:
try:
record = [Link](file)
print("Roll:", record[0], "Name:", record[1])
except EOFError:
break
except FileNotFoundError:
print("No records found.")
def modify_record(roll_no):
records = []
found = False
try:
with open("[Link]", "rb") as file:
while True:
try:
record = [Link](file)
if record[0] == roll_no:
record[1] = input("Enter new name: ")
found = True
[Link](record)
except EOFError:
break
except FileNotFoundError:
print("No records found.")
return
with open("[Link]", "wb") as file:
for record in records:
[Link](record, file)
if found:
print("Record modified.")
else:
print("Roll number not found.")
def delete_record(roll_no):
records = []
found = False
try:
with open("[Link]", "rb") as file:
while True:
try:
record = [Link](file)
if record[0] != roll_no:
[Link](record)
else:
found = True
except EOFError:
break
except FileNotFoundError:
print("No records found.")
return
with open("[Link]", "wb") as file:
for record in records:
[Link](record, file)
if found:
print("Record deleted.")
else:
print("Roll number not found.")
while True:
print("\nMenu:")
print("1. Add Record")
print("2. Display Records")
print("3. Modify Record")
print("4. Delete Record")
print("5. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
add_record()
elif choice == 2:
display_records()
elif choice == 3:
rn = int(input("Enter roll number to modify: "))
modify_record(rn)
elif choice == 4:
rn = int(input("Enter roll number to delete: "))
delete_record(rn)
elif choice == 5:
break
else:
print("Invalid choice.")