PYTHON PROGRAM-8
TEXT FILES
Create a text file [Link] with some data of your own choice in it. Write functions
to do the following operations
Define a function LongLines() which reads the content of the text file named
[Link] and display those lines from the file which has at least 10 words in
it.
Define a function Count_Dwords() in python to count the words ending with
a digit in the text file [Link]
Define a function capital() to read the text file [Link] and capitalizes the
first letter of every word in the file.
Define a function Reverse() which reverses the line starting with I otherwise
display in the normal order.
Source code:
fname='[Link]'
def create():
f=open(fname,'w')
s=[]
while True:
d=input('enter data:')
[Link](d+ '\n')
ch=input('more records?')
if [Link]()=='N':
break
[Link](s)
[Link]()
def LongLines():
f=open(fname)
r=[Link]()
for i in r:
s=[Link]()
if len(s)>=10:
print(i)
[Link]()
def Count_Dwords():
f=open(fname)
r=[Link]()
s=[Link]()
c=0
for i in s:
if i[-1].isdigit():
c+=1
print('count:',c)
[Link]()
def capital():
f=open(fname)
r=[Link]()
for i in r:
c=[Link]()
print(c)
def Reverse():
f=open(fname)
r=[Link]()
for i in r:
s=[Link]()
if s[0]=='I':
print(s[::-1])
else:
print(s)
[Link]()
create()
while True:
print('[Link] lines from the file which have at least 10 words ')
print('[Link] the words ending with a digit')
print('[Link] the first letter of every word in the file')
print('4. reverses the line starting with I ')
ch=int(input('enter choice:'))
if ch==1:
LongLines()
elif ch==2:
Count_Dwords()
elif ch==3:
capital()
elif ch==4:
Reverse()
else:
print('Invalid choice')
break
Output