0% found this document useful (0 votes)
30 views

Text Files workbook

For students

Uploaded by

krithikkumar2589
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
30 views

Text Files workbook

For students

Uploaded by

krithikkumar2589
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 8
Long Answer Type Questions 1. Write a function in Python to count uppercase character in a text file. 2. Write a function NUCount() in Python, which should read each character of a text file STORY.TXT, should count and display the occurrence of alphabets N and U (including small cases n and u too). If the file content is as follows: 3. New research shows th of the cognitive, understanding of The NUCount() hat our closest evolutionary relatives have all Capacities required for cooking except an f how to control fire function should display the output as: 13 Write a function CountDig() in Python, which reads the content of text file "story.txt" and displays the number of digits in it. e.g. ifthe file contains: Amrapali was a queen of Gareware kingdom in the year 1911. She had 2 daughters. Her palace had 200 rooms. Then the output on the screen should be Number of digits in story: 8 Aditi has used a text editing software to type some text. After saving the article as WORDS.TXT, she realised that she has wrongly typed alphabet J in place of alphabet I everywhere in the article, . Write a function definition for JTOI() in Python that would display the corrected version of entire content of the file WORDS.TXT with all the alphabets ")’ to be displayed as an alphabet 'I" on screen. Note: Assuming that WORD.TXT does not contain any J alphabet otherwise, Example; If Aditihas stored the following content in the file WORDS.TXT: WELL, THYS JS A WORD BY. JTSELF, YOU COULD STRETCH THJS TO 6. BE A SENTENCE . The function JTOI() should display the following content: WELL, THIS IS A WORD BY ITSELF. YOU COULD STRETCH THIS TO BE ASENTENCE Write a function EUCount() in Python, which should read each character of a text file STORY.TXT, should count and display the occurrences of alphabets E and U (including small cases e andu too).Example: If the file content is as follows: Updated information As simplified by official websites. The EUCount() function should display the output as: Eore:4 Uorwl A text filenamed MESSAGE.TXT contains some text. Another text file named SMS.TXT needs to be created such that it would store only the first 150 characters from the file MESSAGE.TXT. Write auser-defined function LongToShort() in Python that would perform the above task of creating SMS.TXT from the already existing file MESSAGE. TXT. Atext filenamed "MATTER.TXT" contains some text, which needs to be displayed such that every next character is separated by a symbol "g", Write a function definition for hash_display() in Python that would display the entire content of the file matter.txt in the desired format. Example: Ifthe file matter.txt has the following content stored in it : THE WORLD IS ROUND The function hash_display() should display the following content : T#H#E# #W#O#R#L#D# #1¥S# #R¥O#URNEDE Write function definition for WORDABSTART () in Python to read the content of a text file JOY.TXT, and display all those words, which are starting with either ‘A’, 'a' or 'B, 'b'. e.g, If the content of the file JOY.TXT is as follows: : "Tlove to eat apples and bananas. I was travelling to Ahmedabad to buy some clothes." The function WORDABSTART() should display the following: “apples and bananas Ahmedabad buy" 10. 11. A text file named CONTENTS.TXT contains some text. Write a user- defined function LongWords() in Python which displays all such words of the file whose length is more than 9 alphabets. For example: if the file CONTENTS.TXT contains: "Conditional statements of Python programming language are if and nested if" Then the function LongWords() should display the output as : Conditional statements programming Write a function in Python to read the content of text file "DELHI.TXT" and display all lines on screen, which are either starting with’'E' or starting with 'M’. A text file named NOTES.TXT contains some text. Another text file named COPY.TXT needs to be created such that it would store only lines from the file NOTES. TXT those are not staring with letter T. Write a function in Python to perform above task. 12, Write a function in Python, which reads the contents of a text file 13. “diary.txt" and counts the words His and Her (not case sensitive). e.g. if the file contains: Pinaky has gone to his friend's house. His friend's name is Ravya. Her house is 12 KM from here. The function should display the output as Count for His: 2 Count for Her: 1 Write function definition for count_success() in Python to read the content of a text file STORY.TXT, count the presence of word SUCCESS and display the number of occurrence of this word. NOTE -The word SUCCESS should be an independent word -Ignore type cases (i.e. lower/upper case) eg. ifthe content of the file STORY.TXT is as follows: ; "Success shows others that we can doit. It is possible to achieve success with hard work. Lot of money does not mean SUCCESS The function count_success() should display the following: 3 14. Write a function CountYouMe() in Python, which reads the content of 15. a text file "story.txt" and counts the words You and Me (not case sensitive). e.g. if the file contains: You are my best friend. You and me make a good team. The function should display the output as Count for You: 2 Count for Me: 1 Write a function in Python to count the number of "He" or "She" words present in a text file "STORY.TXT". If the file "STORY.TXT" content is as follows: He is playing in the ground. She is playing with her dolls. The output of the function should be Count of He/She in file:2 16. Write a function in Python that counts the number of "Me" or "My" words present in a text file "STORY.TXT". If the "STORY.TXT" contents are as follows: My first book was Me and My Family. It gave me chance to be Known to the world. The output of the function should be: Count of Me in file: 2 Count of My in file: 2

You might also like