0% found this document useful (0 votes)
27 views5 pages

Program 4

The document describes a menu driven program that allows a user to add records to a text file, display all records, search for a particular record, and quit. The program contains functions to add records to a file, read and display all records of the file, and search for a specific record by roll number.

Uploaded by

vaishnavi
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)
27 views5 pages

Program 4

The document describes a menu driven program that allows a user to add records to a text file, display all records, search for a particular record, and quit. The program contains functions to add records to a file, read and display all records of the file, and search for a specific record by roll number.

Uploaded by

vaishnavi
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
You are on page 1/ 5

PROGRAM-4

A text file Records.txt contains information of a student


(Rno, Name , marks).
Write a menu driven program which does the following
1. Add records to the file
2. Display the records
3. Search for a particular record
4. Quit

fname="C:\\temp\\Records.txt"
def fileadd(fname):
f=open(fname,"a")
s=[]
ch='y'
while ch=='y' or ch=='Y':
rno=input("Enter the roll no :")
f.write(rno)
f.write(',')
name=input("Enter the name:")
f.write(name)
f.write(',')
marks=input("Enter the marks:")
f.write(marks)
ch=input("Do u want to continue Y/N ?")
f.write('\n')
f.close()
def fileread(fname):
f1=open(fname)
r=f1.readlines()
for i in r:
print(i)
f1.close()
def search(fname):
flag=0
f=open(fname)
rno=input("Enter the roll no to be searched: ")
while True:
n=f.readline()
rollno=''
for k in n:
if k == ',':
break
else:
rollno=rollno+k
if rollno == rno:
print('STUDENT FOUND')
print('*******************************')
print(n)
print('*******************************')
flag=1
break
if flag==0:
print("STUDENT NOT FOUND")
ch=0
while ch!=4:
print("STUDENT DETAILS")
print("1.ADDING RECORDS")
print("2.DISPLAYING RECORDS")
print("3.SEARCH FOR A PARTICULAR RECORD")
print("4.QUIT")
ch=int(input("Enter ur choice: "))
if ch==1:
fileadd(fname)
elif ch==2:
fileread(fname)
elif ch==3:
search(fname)
elif ch==4:
break
else:
print("Wrong choice")
OUTPUT

You might also like