Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

LAB-7

Write an interactive menu driven program which


does the following →
● Create a text file school.txt with admission
number, name and class of a particular student
● Display the file content
● Create another file Uschool.txt with the details n
uppercase
● Exit

fname1='school.txt’
fname2='Uschool.txt’
def create():
f=open(fname1,'a')
while True:
admno=input('ADMISSION NO:')
n=input('NAME:')
Class=input('CLASS:')
s.append(admno+','+n+','+Class+'\n')
q=input('more records? (Y/N):')
if q.upper()=='N':
break
f.writelines(s)
f.close()
def display():
f=open(fname1)
r=f.read()
print(r)
f.close()
def Upper():
f=open(fname1)
f1=open(fname2,'a')
1|Page
r=f.read()
f1.write(r.upper())
f.close()
f1.close()
def show():
f1=open(fname1)
f2=open(fname2)
r1=f1.read()
print(r1)
r2=f2.read()
print(r2)
f1.close()
f2.close()
while True:
print('1.Create records')
print('2.Display original file')
print('3.Create duplicate file in uppercase')
print('4.Display both files')
print('5.Quit)
ch=int(input('enter your choice:'))
if ch==1:
create()
elif ch==2:
display()
elif ch==3:
Upper()
elif ch==4:
show()
elif ch==5:
break
else:
print('Invalid choice')

2|Page

You might also like