Programs of Text File
Programs of Text File
1. WRITE A PROGRAM TO PRINT THE NUMBER OF OCCURRENCE OF WORD “HAPPY” OR “happy” IN THE
GIVEN FILE.
2. WAP TO COUNT THE TOTAL NUMBER OF UPPERCASE, LOWERCASE LETTERS AND DIGITS USED IN THE
TEXT FILE ‘POEM.TXT’
3. WRITE A PYTHON FUNCTION THAT DISPLAYS ALL THE LINES CONTAINING THE WORD ‘vote’ FROM A
TEXT FILE ‘ELECTION.TXT’.
4. WRITE A PYTHON FUNCTION THAT DISPLAYS ALL THE WORDS STARTING AND ENDING WITH A VOWEL
FROM A TEXT FILE ‘REPORT.TXT’. THE CONSECUTIVE WORDS SHOULD BE SEPARATED BY A SPACE IN
THE OUTPUT.
5. Write code for the following:
i) Define a function to create a text file ‘poem.txt’ and stores 5 lines of text in it.
ii) Define a function to accept a list [‘a’,’an’,’the’0 and count the occurrence of each item
of list in the text file ‘poem.txt’ separately.
6. Write a function CAPITALIZE_EACH_WORD() in Python that read the words from file “para.txt” and
copy those words to another file “words.txt” after capitalizing the first letter of each word.
7. Manish created a text file named ‘city.txt’ to store names of 5 cities. He wrote set of statements to
carry out the task but he has doubt in many statements therefore he left blank at those places. Look
carefully the following code and help him to complete the program code.
Def add():
Now
q= open(‘city.txt’,_______) # statement 1
n=[‘Delhi\n’,’Kolkata\n’,’Mumbai\n’,Kanpur\n’,’Dispur\n’]
____________ #statement 2
q.close()
def display():
with open(‘city.txt’) as q:
____________________ # statement 3
for i in r:
G=i.strip()
for ‘a’ not in g:
print(g.capitalize(),end=’@’)
q.close()
add()
display()