Program 4
Program 4
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