Class 12 CS Chapter 5 File Handling Solutions Sumita Arora New Syllabus / Uncategorized / By Neha Ex 5.1 Solutions 1. In which of the following file modes, the existing data of file will not be lost ? ...click here for answer 2. What would be the data type of variable data in following statements ? ...click here for answer 3. How are following statements different ? ...click here for answer Back Exercise Part A 1. What is the difference between “w” and “a” modes ? ...click here for answer 2. What is the significance of file-object ? ...click here for answer 3. How is file open( ) function different from close( ) function ? ...click here for answer 4. Write statements to open a binary file C:\Myfiles\Textl.txt in read and write mode by specifying the file path in two different formats. ...click here for answer 5. When a file is opened for output, what happens when ...click here for answer 6. What role is played by file modes in file operations ? Describe the various file mode constants and their meanings. ...click here for answer 7. What are the advantages of saving data in : (i) binary form (it) text form ? ...click here for answer 9. Write a statement in Python to perform the following operations : ...click here for answer Back Exercise Part B 2. If the file ‘poemBTH.txt’ contains the following poem (by Paramhans Yoganand) : ...click here for answers 1. How are following codes different from one another ? ...click here for answers 3. Consider the file poemBTH.txt given above (in previous question). What output will be produced by following code fragment ? ...click here for answers 4. Consider the file “poemBTH.txt” and predict the outputs of following code fragments if the file has been opened in filepointer filel with code: ...click here for answers 5. What is following code doing ? ...click here for answers 6. Write code to open file created in previous question and print it in following form : ...click here for answers 7. Consider the file “contacts.csv” created in above question and figure out what the following code is trying to do? ...click here for answers 8. Consider the file poemBTH.txt and predict the output of following code fragment. What exactly is following code fragment doing ? ...click here for answers 9. If you use the code of Q.8 with pl.txt created in solved problem 14, what would be its output ? ...click here for answers 10. Write a method in python to read the content from a text file diary.txt line by line and display the same on screen. ...click here for answers 11. Write a method in python to write multiple line of text contents into a text file mylife.txt.line. ...click here for answers Back Exercise Part C 2. A file sports.dat contains information in following format : Event ~ Participant Write a function that would read contents from file sports.dat and creates a file named Atheletic.dat copying only those records from sports.dat where the event name is “Atheletics”. ...click here for answer 3. A file contains £ list of telephone numbers in the following form : ...click here for answer 4. Write a program to count the words “to” and “the” present in a text file “Poem.txt”. ...click here for answer 5. Write a program to count the number of upper- case alphabets present in a text file “Article.txt”. ...click here for answer 6. Write a program that copies one file to another. Have the program read the file names from user ? ...click here for answer 7. Write a program that appends the contents of one file to another. Have the program take the filenames from the user. ...click here for answer 8. Write a program that reads characters from the keyboard one by one. All lower case characters get stored inside the file LOWER, all upper case characters get stored inside the file UPPER and all other characters get stored inside file OTHERS. # Code ...click here for answer 9. Write a function in Python to count and display the number of lines starting with alphabet ‘A’ present in a text file ” LINES.TXT”. e.g., the file “LINES.TXT” contains the following lines : A boy ...click here for answer