0% found this document useful (0 votes)
0 views2 pages

Menu Driven Python Program To Maintain Students Record in Text File

This document outlines a Python program for managing student records in a text file. It includes functions to add, display, update, and remove student data, with a menu-driven interface for user interaction. The program allows users to input student details and manipulate the records stored in 'studentlist'.

Uploaded by

uma divan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

Menu Driven Python Program To Maintain Students Record in Text File

This document outlines a Python program for managing student records in a text file. It includes functions to add, display, update, and remove student data, with a menu-driven interface for user interaction. The program allows users to input student details and manipulate the records stored in 'studentlist'.

Uploaded by

uma divan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

*****MENU DRIVEN PYTHON PROGRAM TO MAINTAIN STUDENTS RECORD IN TEXT

FILE****
def add_data():
n=int(input("Enter the no of records to be entered"))
for i in range(n):
f=open("studentlist","a")
sid=input("enter id")
sname=input("enter name")
sclas=input("enter class")
score=input("enter score")

record = [sid, sname, sclas, score]


line = ",".join(record) + "\n"
f.writelines(line)
f.close()

def display():
f=open("studentlist","r")
data=f.read()
print(data)
f.close()

def update_data():
f = open("studentlist", "r")
rec = f.readlines()
print(rec)
f.close()

f1 = open("studentlist", "w")
id_to_update = input("Enter the ID to update: ")

for i in rec:
sid, name, sclass, score = i.strip().split(",")
if sid == id_to_update:
name = input("Enter new name: ")
sclass = input("Enter new class: ")
score = input("Enter new score: ")
new_record = ",".join([sid, name, sclass, score]) + "\n"
f1.write(new_record)
else:
f1.write(i)
f1.close()
def remove_data():
f = open("studentlist", "r")
rec = f.readlines()
print(rec)
f.close()

f1 = open("studentlist", "w")
id_to_update = input("Enter the ID to update: ")

for i in rec:
sid, name, sclass, score = i.strip().split(",")
if sid != id_to_update:
f1.write(i)
f1.close()

menu="""
STUDENT RECORDS MANAGEMENT
1)ADD DATA
2)DISPLAY DATA
3)UPDATE DATA
4)REMOVE DATA
5)EXIT
"""
while True:
print(menu)
ch=int(input("enter your choice"))
if ch==1:
add_data()
elif ch==2:
display()
elif ch==3:
update_data()
elif ch==4:
remove_data()
else:
break

You might also like