XII-CS WS5 (CH. 6 File Handling)
XII-CS WS5 (CH. 6 File Handling)
Q 1. Write a program to count the total no. of characters (including spaces) from a file
"book.txt".
Q 3. Write a program to count the number of characters (without space) from a file
"book.txt".
Q 4. Write a program that prints the contents of a text file on the screen. The name of
text file is to be accepted by the user. Also tell the size of file in bytes.
Q 5. Write a function in Python to count the number of vowels present in a text file
“STORY.TXT”.
Q 7. Write a function in Python to print the count of the word “and” (including “And”,
“AND” too) in the text file “STORY.TXT”.
Q 8. Write a function in Python to read the content of a text file “DELHI.TXT” and
display all those lines on screen, which are either starting with ‘D’ or ‘M’.
Q 11. A binary file “student.dat” has structure (RollNo, Name, Percentage). Write a
function CountNinty( ) in Python that would read contents of the file “student.dat”
and display the details of those students whose percentage is 90 and above. Also
display number of students scoring above 90%.
Q 12. Radha is a programmer, who has recently been given a task to write a python
code to perform the following CSV file operations with the help of two user
defined functions/modules:
a. CSVOpen() : to create a CSV file called BOOKS.CSV in append mode
containing information of books – Title, Author and Price.
b. CSVRead() : to display the records from the CSV file called BOOKS.CSV
where the field title starts with 'R'.
Q 13. Write the definition of a function ChangeGender() in Python, which reads the
contents of a text file "BIOPIC.TXT" and displays the content of the file with every
occurrence of the word 'he' replaced by 'she'.
The function should read the file content and display the output as follows :
Last time she went to Agra,
there was too much crowd, which she did not like.
So this time she decided to visit some hill station.
Q 14. Write the definition of a function Count_Line() in Python, which should read
each line of a text file "SHIVAJI.TXT" and count total number of lines present in
text file.
For example, if the content of the file "SHIVAJI.TXT" is as follows :
Shivaji was born in the family of Bhonsle.
He was devoted to his mother Jijabai.
India at that time was under Muslim rule.
The function should read the file content and display the output as follows :
Total number of lines : 3