0% found this document useful (0 votes)
11 views12 pages

Text File Programs

Uploaded by

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

Text File Programs

Uploaded by

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

Write a program to count number of word from a text

file “story.txt” which is starting with uppercase


character, lowercase character, digit and special
character.

Example:
Happy new year 2020.

No of upper case=1
No of lower case=2
No of digit=1
No of special =0
F=open(“HELLO.TXT”,’r’)
s=F.read()
L=s.split()
u=d=l=s=0
for i in L:
if i[0].isupper():
u+=1
elif i[0].islower():
l+=1
elif i[0].isdigit():
d+=1
else:
s+=1
print(u)
print(l)
print(d)
print(s)
F.close()
Write a program to count number of word
from a text file “Story.txt” which is staring
with “the”, ”The”, ”my” and “My”.

Example:
They are playing. Myself Alex. The sky is
blue. Where is my pen?

The number of such word=4


F=open(“story.txt”,’r’)
s=F.read()
L=s.split()
c=0
for i in L:
if i[:3]=="the" or i[:3]=="The" or i[:2]=="my" or
i[:2]=="My":
c+=1
print(c)
F.close()
Write a program to display those line from a text file
“Read.txt” which contain at least 2 word which is
starting with vowel.

Example:
I am very excited to know about you.
He likes to do Mathematics.
I am not part of it.

Output:
I am very excited to know about you.
I am not part of it.
F=open(“story.txt”,’r’)
S=F.readlines()
for i in S:
c=0
l=i.split()
for w in l:
if w[0] in "AEIOUaeiou":
c+=1
if c>=2:
print(i)
F.close()
Write a program to change the content of
the text file “Hello.txt” into toggle case from
Sentence case.

Example:
They Are Playing In The Ground.

Output:
tHEY aRE pLAYING iN tHE gROUND.
Write a program to display the Flight details of
those flight which is starting from “Mumbai”
and going to “Kolkata” from a binary file
“Flight.dat”.
Content of the binary file is
FL_NO FL_NAME FL_DEPT FL_ARI FL_PASNGR

F01 SPICE JET Mumbai Kolkata 200


F02 INDIGO Delhi Mumbai 300
F03 AIR INDIA Mumbai Kolkata 400

You might also like