2024 08 06 09 54 Solution
2024 08 06 09 54 Solution
Section B
1. A text file “Quotes.Txt” has the following data written in it: "Living a life you can
be proud of Doing your best Spending your time with people and activities that
are important to you Standing up for things that are right even when it’s hard
Becoming the best version of you." Write a user defined function to display the
total number of words present in the file.
Ans. :
2. Write a python program to accept a line from the user and store that in a file
“story.txt”.
Ans. :
3. Write a python program to accept the multiple lines from the user and store is
into the file.
Page 1
Ans. :
4. Write the python program using writelines() function to store the following
data:
[Filename: ch4/ch-4_Q10]
Ans. :
6. Write a program to read the content of the file line by line and display.
Assuming that file name is “multiline.txt”.
Ans. :
7. Write a program to Read the content of the file line by line and print without
‘n’. Assuming that file name is “multiline.txt”.
Page 2
Ans. :
8. Write a function countmy( )in Python to read the text file "DATA.TXT" and count
the number of times "my" occurs in the file. For example if the file "DATA.TXT"
contains: "This is my website. I have displayed my preferences in the CHOICE
section." The countmy( ) function should display the output as: "my occurs 2
times".
Ans. :
9. Write a method in Python to read lines from a text file INDIA.TXT, to find and
display the occurrence of the word "India".
Page 3
Ans. :
10. Write a function to count the “me” and “my” in a file “India.txt”.
Ans. :
11. Write a function to count the Upper case vowel in file “All.txt”.
Ans. :
12. Write a function to copy all the upper case words to another file.
Page 4
Ans. :
13. Write a function to display the alternate lines from the file.
Ans. :
14. Write a function to read the content from the file and display each word in
reverse order.
Ans. :
15. Write a function to read the content from the file and print all the upper case
word.
Page 5
Ans. :
16. Write a function to read the content from the file “Story.txt”. The function will
take a string as parameter and search the string into the file.
Ans. :
----- -----