- Polina Raj has used a text editing software to type some text in an article. After saving the article as MYNOTES.TXT , she realised that she has wrongly typed alphabet K in place of alphabet C everywhere in the article.
- a) Write a function definition for PURETEXT() in Python that would display the corrected version of the entire article of the file MYNOTES.TXT with all the alphabets “K” to be displayed as an alphabet “C” on screen .
Note: Assuming that MYNOTES.TXT does not contain any C alphabet otherwise.
Example:
If Polina has stored the following content in the file MYNOTES.TXT :
I OWN A KUTE LITTLE KAR.
I KARE FOR IT AS MY KHILD.
The function PURETEXT() should display the following content:
I OWN A CUTE LITTLE CAR.
I CARE FOR IT AS MY CHILD.
- b) Create another function CORRECTEXT() to write the modified text into the same file MYNOTES.TXT.
- A text file named MESSAGE.TXT contains some text. Write a program to create a dictionary that contains all the unique characters in the file with their count (No of occurrence).
Example: If MESSAGE.TXT file contains: HELLO HOW ARE YOU! Then the dictionary should contains: {'H' : 2 ,'E' : 2 ,'L' : 2 ,'O' : 3,'W' : 1 ,'A' : 1 , 'R' : 1 , 'Y' : 1 , 'U' : 1 , '!' : 1 , ' ' : 3}
- A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].
- Write a user-defined function CreateFile() to input data for a record and add to Book.dat .
- Write a function CountRec(Author) in Python which accepts the Author name as parameter and count and return number of books by the given Author are stored in the binary file “Book.dat”.
Click Here for Solution - A binary file “STUDENT.DAT” has structure (admission_number, Name, Percentage). Write a function countrec() in Python that would read contents of the file “STUDENT.DAT” and display the details of those students whose percentage is above 75. Also display number of students scoring above 75%.
Click Here for Solution
No comments:
Post a Comment