{"id":1544,"date":"2021-11-28T22:00:18","date_gmt":"2021-11-28T16:30:18","guid":{"rendered":"https:\/\/cbsepython.in\/?p=1544"},"modified":"2021-11-29T13:09:18","modified_gmt":"2021-11-29T07:39:18","slug":"python-file-handling-mcq-class-12","status":"publish","type":"post","link":"https:\/\/cbsepython.in\/python-file-handling-mcq-class-12\/","title":{"rendered":"Must Prepare Python File Handling MCQ Class 12 for Term 1"},"content":{"rendered":"<h2>Must Prepare Python File Handling MCQ Class 12 for Term 1<\/h2>\n<h3><span style=\"color: #000000;\">MCQ on Writing\/appending data to a text file using write() and writelines(), <\/span><\/h3>\n<h3><span style=\"color: #000000;\">Reading from a text file using read(), readline( ) and readlines()<\/span><\/h3>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">1. The ____________ method returns a list containing each line of the file as a list item.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) read()<\/span><\/p>\n<p><span style=\"color: #000000;\">b) readline()<\/span><\/p>\n<p><span style=\"color: #000000;\">c) readlines()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) readone()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104800258079834901' value='69d8b104800258079834901'><input type='hidden' id='bg-show-more-text-69d8b104800258079834901' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104800258079834901' value='Hide Answer'><button id='bg-showmore-action-69d8b104800258079834901' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104800258079834901' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) readlines()<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">2. If we want to write a sequence of strings,list, tuple into the file then we use _________ function.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) write()<\/span><\/p>\n<p><span style=\"color: #000000;\">b) writelines()<\/span><\/p>\n<p><span style=\"color: #000000;\">c) writerow()<\/span><\/p>\n<p><span style=\"color: #000000;\">d) append()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048022e8036731548' value='69d8b1048022e8036731548'><input type='hidden' id='bg-show-more-text-69d8b1048022e8036731548' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048022e8036731548' value='Hide Answer'><button id='bg-showmore-action-69d8b1048022e8036731548' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048022e8036731548' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) writelines()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">3. read() and readline() functions can be used for reading no of characters from file if size is mentioned.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) read() and readline()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) readlines() and readline()<\/span><\/p>\n<p><span style=\"color: #000000;\">c) read() and readlines()<\/span><\/p>\n<p><span style=\"color: #000000;\">d) None of the above<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104803870096079088' value='69d8b104803870096079088'><input type='hidden' id='bg-show-more-text-69d8b104803870096079088' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104803870096079088' value='Hide Answer'><button id='bg-showmore-action-69d8b104803870096079088' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104803870096079088' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) read() and readline()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">4. We can use readline( ) function which can read one line at a time from the file.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) read() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) readline()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) readlines() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) readone()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104804917055933354' value='69d8b104804917055933354'><input type='hidden' id='bg-show-more-text-69d8b104804917055933354' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104804917055933354' value='Hide Answer'><button id='bg-showmore-action-69d8b104804917055933354' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104804917055933354' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) readline()<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">5. To read twelve characters from a file object fin we use ________<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) fin.read(12)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) fin.read() <\/span><\/p>\n<p><span style=\"color: #000000;\">c) fin.readline() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) read(12)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104805a22052579299' value='69d8b104805a22052579299'><input type='hidden' id='bg-show-more-text-69d8b104805a22052579299' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104805a22052579299' value='Hide Answer'><button id='bg-showmore-action-69d8b104805a22052579299' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104805a22052579299' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) fin.read(12)<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">6. Python automatically flushes the file buffers before closing a file with close() function.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) True\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) False<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104806966032741752' value='69d8b104806966032741752'><input type='hidden' id='bg-show-more-text-69d8b104806966032741752' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104806966032741752' value='Hide Answer'><button id='bg-showmore-action-69d8b104806966032741752' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104806966032741752' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) True<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">7. The ________ method in Python file handling clears the internal buffer of the file..<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) close() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) flush()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) clear() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) open()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048077c2092918570' value='69d8b1048077c2092918570'><input type='hidden' id='bg-show-more-text-69d8b1048077c2092918570' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048077c2092918570' value='Hide Answer'><button id='bg-showmore-action-69d8b1048077c2092918570' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048077c2092918570' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) flush()<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">8. Suppose content of &#8216;Myfile.txt&#8217; is<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">Humpty Dumpty sat on a wall<\/span><\/p>\n<p><span style=\"color: #000000;\">Humpty Dumpty had a great fall<\/span><\/p>\n<p><span style=\"color: #000000;\">All the king&#8217;s horses and all the king&#8217;s men<\/span><\/p>\n<p><span style=\"color: #000000;\">Couldn&#8217;t put Humpty together again<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">What will be the output of the following code?<\/span><\/p>\n<p><span style=\"color: #000000;\">myfile = open(&#8220;Myfile.txt&#8221;)<\/span><\/p>\n<p><span style=\"color: #000000;\">record = myfile.read().split()<\/span><\/p>\n<p><span style=\"color: #000000;\">print(len(record))<\/span><\/p>\n<p><span style=\"color: #000000;\">myfile.close()<\/span><\/p>\n<p><span style=\"color: #000000;\">a) 24 <\/span><\/p>\n<p><span style=\"color: #000000;\">b) 25 <\/span><\/p>\n<p><span style=\"color: #000000;\">c) 26\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) 27<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104808909055930659' value='69d8b104808909055930659'><input type='hidden' id='bg-show-more-text-69d8b104808909055930659' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104808909055930659' value='Hide Answer'><button id='bg-showmore-action-69d8b104808909055930659' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104808909055930659' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) 26\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">9. To create a new file or to write on an existing file after truncating \/ overwriting its old content , file has to be opened in _______ access mode<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) \u201cw+\u201d\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) \u201ca+\u201d <\/span><\/p>\n<p><span style=\"color: #000000;\">c) \u201cr+\u201d <\/span><\/p>\n<p><span style=\"color: #000000;\">d) \u201cwb\u201d<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104809a47014362016' value='69d8b104809a47014362016'><input type='hidden' id='bg-show-more-text-69d8b104809a47014362016' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104809a47014362016' value='Hide Answer'><button id='bg-showmore-action-69d8b104809a47014362016' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104809a47014362016' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) \u201cw+\u201d\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">10. Which of the following options can be used to read the first line of a text file Myfile.txt?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) myfile = open(&#8216;Myfile.txt&#8217;); myfile.read()<\/span><\/p>\n<p><span style=\"color: #000000;\">b) myfile = open(&#8216;Myfile.txt&#8217;,&#8217;r&#8217;); myfile.read(n)<\/span><\/p>\n<p><span style=\"color: #000000;\">c) myfile = open(&#8216;Myfile.txt&#8217;); myfile.readline()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) myfile = open(&#8216;Myfile.txt&#8217;); myfile.readlines()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10480ac16004547715' value='69d8b10480ac16004547715'><input type='hidden' id='bg-show-more-text-69d8b10480ac16004547715' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10480ac16004547715' value='Hide Answer'><button id='bg-showmore-action-69d8b10480ac16004547715' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10480ac16004547715' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) myfile = open(&#8216;Myfile.txt&#8217;); myfile.readline()<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">11. Which of the following options can be used to read the whole content of a text file Myfile.txt?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) myfile = open(&#8216;Myfile.txt&#8217;); myfile.read()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) myfile = open(&#8216;Myfile.txt&#8217;,&#8217;r&#8217;); myfile.read(n)<\/span><\/p>\n<p><span style=\"color: #000000;\">c) myfile = open(&#8216;Myfile.txt&#8217;); myfile.readline()<\/span><\/p>\n<p><span style=\"color: #000000;\">d) myfile = open(&#8216;Myfile.txt&#8217;); myfile.readlines()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10480c195096957660' value='69d8b10480c195096957660'><input type='hidden' id='bg-show-more-text-69d8b10480c195096957660' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10480c195096957660' value='Hide Answer'><button id='bg-showmore-action-69d8b10480c195096957660' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10480c195096957660' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) myfile = open(&#8216;Myfile.txt&#8217;); myfile.read()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>12. To open a file for reading any of the following statement can be used :<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) f = open(&#8220;demofile.txt&#8221;) <\/span><\/p>\n<p><span style=\"color: #000000;\">b) f = open(&#8220;demofile.txt&#8221;, &#8220;rt&#8221;) <\/span><\/p>\n<p><span style=\"color: #000000;\">c) f = open(&#8220;demofile.txt&#8221;, &#8220;r&#8221;) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) All of the above\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10480d309053964641' value='69d8b10480d309053964641'><input type='hidden' id='bg-show-more-text-69d8b10480d309053964641' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10480d309053964641' value='Hide Answer'><button id='bg-showmore-action-69d8b10480d309053964641' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10480d309053964641' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">d) All of the above\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>13. Suppose content of &#8216;Myfile.txt&#8217; is: Twinkle twinkle little star How I wonder what you are Up above the world so high Like a diamond in the sky What will be the output of the following code?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">myfile = open(&#8220;Myfile.txt&#8221;) <\/span><\/p>\n<p><span style=\"color: #000000;\">data = myfile.readlines()<\/span><\/p>\n<p><span style=\"color: #000000;\"> print(len(data)) <\/span><\/p>\n<p><span style=\"color: #000000;\">myfile.close() <\/span><\/p>\n<p><span style=\"color: #000000;\">a) 3 <\/span><\/p>\n<p><span style=\"color: #000000;\">b) 4\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) 5 <\/span><\/p>\n<p><span style=\"color: #000000;\">d) 6<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10480e6a1086433505' value='69d8b10480e6a1086433505'><input type='hidden' id='bg-show-more-text-69d8b10480e6a1086433505' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10480e6a1086433505' value='Hide Answer'><button id='bg-showmore-action-69d8b10480e6a1086433505' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10480e6a1086433505' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) 4<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>14. Suppose content of &#8216;Myfile.txt&#8217; is Culture is the widening of the mind and of the spirit. What will be the output of the following code?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">myfile = open(&#8220;Myfile.txt&#8221;) <\/span><\/p>\n<p><span style=\"color: #000000;\">x = myfile.read()<\/span><\/p>\n<p><span style=\"color: #000000;\"> y = x.count(&#8216;the&#8217;) <\/span><\/p>\n<p><span style=\"color: #000000;\">print(y) <\/span><\/p>\n<p><span style=\"color: #000000;\">myfile.close() <\/span><\/p>\n<p><span style=\"color: #000000;\">a) 2 <\/span><\/p>\n<p><span style=\"color: #000000;\">b) 3\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) 4 <\/span><\/p>\n<p><span style=\"color: #000000;\">d) 5 <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10480f689019188358' value='69d8b10480f689019188358'><input type='hidden' id='bg-show-more-text-69d8b10480f689019188358' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10480f689019188358' value='Hide Answer'><button id='bg-showmore-action-69d8b10480f689019188358' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10480f689019188358' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) 3\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<h2>Don&#8217;t Miss Topics:<\/h2>\n<h3><a href=\"https:\/\/cbsepython.in\/text-file-mcq-question-bank-for-class-12\/\">50+ Most Important Text File MCQ for Term 1 (Including CASE BASED MCQ)<\/a><\/h3>\n<h3><a href=\"https:\/\/cbsepython.in\/binary-file-mcq-question-bank-for-class-12\/\">60+ Most Important Binary File MCQ for Term 1 (Including CASE BASED MCQ)<\/a><\/h3>\n<h3><a href=\"https:\/\/cbsepython.in\/csv-file-mcq-question-bank-for-class-12\/\">40+ Most Important CSV File MCQ for Term 1(Including CASE BASED MCQ)<\/a><\/h3>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">CASE STUDY QUESTIONS\u00a0<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #000000;\">15. Atif has been asked by his senior to complete the following code. The code uses a text file namely message.txt.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">def count_words(filename):<\/span><\/p>\n<p><span style=\"color: #000000;\">Bigwords=0<\/span><\/p>\n<p><span style=\"color: #000000;\">F=open(filename,\u201fr\u201f)<\/span><\/p>\n<p><span style=\"color: #000000;\">Data=F.___________ # line 1<\/span><\/p>\n<p><span style=\"color: #000000;\">words = _____________ # line 2<\/span><\/p>\n<p><span style=\"color: #000000;\">For w in words :<\/span><\/p>\n<p><span style=\"color: #000000;\">__________ # line 3<\/span><\/p>\n<p><span style=\"color: #000000;\">___________# line 4<\/span><\/p>\n<p><span style=\"color: #000000;\">return bigwords, len(words)<\/span><\/p>\n<p><span style=\"color: #000000;\">_______ # line 5<\/span><\/p>\n<p><span style=\"color: #000000;\">print(\u201ctotal number of words : \u201c,count)<\/span><\/p>\n<p><span style=\"color: #000000;\">print(\u201cNo. of big words :\u201d,big)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>15.1) Which function is used to read all the content of the file for line1 and store in Data variable in string format.<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) readline() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) read(file) <\/span><\/p>\n<p><span style=\"color: #000000;\">c) read()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) readlines() <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104810610041681169' value='69d8b104810610041681169'><input type='hidden' id='bg-show-more-text-69d8b104810610041681169' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104810610041681169' value='Hide Answer'><button id='bg-showmore-action-69d8b104810610041681169' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104810610041681169' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) read()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">15.2)Which option is correct for completing line 2<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) Data.split()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) Data.Split() <\/span><\/p>\n<p><span style=\"color: #000000;\">c) f.split() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) None of the above<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104811489075825060' value='69d8b104811489075825060'><input type='hidden' id='bg-show-more-text-69d8b104811489075825060' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104811489075825060' value='Hide Answer'><button id='bg-showmore-action-69d8b104811489075825060' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104811489075825060' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) Data.split()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">15.3) Which option is correct for completing line 3 and line 4 so that the count of words having length more than 8 characters.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) If w&gt;8 : <\/span><\/p>\n<p><span style=\"color: #000000;\">bigwords+=1<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">b) if len(w) &gt;8: <\/span><\/p>\n<p><span style=\"color: #000000;\">bigwords+=1\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">c) if len(w) &gt;=8: <\/span><\/p>\n<p><span style=\"color: #000000;\">bigwords+=1<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">d) if len(w) &gt;8:<\/span><\/p>\n<p><span style=\"color: #000000;\">bigwords+=1<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048128c8009088712' value='69d8b1048128c8009088712'><input type='hidden' id='bg-show-more-text-69d8b1048128c8009088712' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048128c8009088712' value='Hide Answer'><button id='bg-showmore-action-69d8b1048128c8009088712' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048128c8009088712' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) if len(w) &gt;8: <\/span><\/strong><\/p>\n<p><strong><span style=\"color: #000000\">bigwords+=1\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">15.4) Which option is correct for completing line 5 so that function count_words() is called.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) big ,count= count_words(filename)<\/span><\/p>\n<p><span style=\"color: #000000;\">b) big ,count= count_words(\u201cmessage.txt\u201d)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) big _count=count_words(\u201cmessage.txt\u201d)<\/span><\/p>\n<p><span style=\"color: #000000;\">d) big=count_words(\u201cmessage.txt\u201d) count=count_words(\u201cmessage.txt\u201d)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104813ef8099488298' value='69d8b104813ef8099488298'><input type='hidden' id='bg-show-more-text-69d8b104813ef8099488298' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104813ef8099488298' value='Hide Answer'><button id='bg-showmore-action-69d8b104813ef8099488298' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104813ef8099488298' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) big ,count= count_words(\u201cmessage.txt\u201d)<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">16. Teacher has developed a program to count how many lines start with \u201cT\u201d in a text file \u201cstory.txt\u201d. To choose correct option for executing program successfully.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">def countlines():<\/span><\/p>\n<p><span style=\"color: #000000;\">file= _______ (\u201cstory.txt\u201d) #line1<\/span><\/p>\n<p><span style=\"color: #000000;\">data = __________ #line2<\/span><\/p>\n<p><span style=\"color: #000000;\">__________# line 3<\/span><\/p>\n<p><span style=\"color: #000000;\">for I in data :<\/span><\/p>\n<p><span style=\"color: #000000;\">if _______ : # line4<\/span><\/p>\n<p><span style=\"color: #000000;\">c+=1<\/span><\/p>\n<p><span style=\"color: #000000;\">print(\u201cNumber of lines start with T \u201c, _____) #line5<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">16.1) Which function to be used to complete line 1<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) Read() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) open()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) read() <\/span><\/p>\n<p><span style=\"color: #000000;\">d)Open()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104814e87050597659' value='69d8b104814e87050597659'><input type='hidden' id='bg-show-more-text-69d8b104814e87050597659' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104814e87050597659' value='Hide Answer'><button id='bg-showmore-action-69d8b104814e87050597659' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104814e87050597659' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) open()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>16.2) Which function is used to read the content from the file<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) file.read() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) readline() <\/span><\/p>\n<p><span style=\"color: #000000;\">c) file.readlines()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) file.readline() <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104815e55083254067' value='69d8b104815e55083254067'><input type='hidden' id='bg-show-more-text-69d8b104815e55083254067' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104815e55083254067' value='Hide Answer'><button id='bg-showmore-action-69d8b104815e55083254067' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104815e55083254067' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) file.readlines()<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">16.3) Line3- initialize the variable for count<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) c=0\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) c=c+1 <\/span><\/p>\n<p><span style=\"color: #000000;\">c) both <\/span><\/p>\n<p><span style=\"color: #000000;\">d) none<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104816947028988016' value='69d8b104816947028988016'><input type='hidden' id='bg-show-more-text-69d8b104816947028988016' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104816947028988016' value='Hide Answer'><button id='bg-showmore-action-69d8b104816947028988016' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104816947028988016' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) c=0\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">16.4) choose correct condition for line3<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) i==&#8217;T&#8217; <\/span><\/p>\n<p><span style=\"color: #000000;\">b) i[0]==&#8217;T&#8217;\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) &#8220;i&#8221;==T <\/span><\/p>\n<p><span style=\"color: #000000;\">d) i[0]==T<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104817286018363177' value='69d8b104817286018363177'><input type='hidden' id='bg-show-more-text-69d8b104817286018363177' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104817286018363177' value='Hide Answer'><button id='bg-showmore-action-69d8b104817286018363177' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104817286018363177' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) i[0]==&#8217;T&#8217;<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>16.5) complete the line4<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) c\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) count <\/span><\/p>\n<p><span style=\"color: #000000;\">c) I <\/span><\/p>\n<p><span style=\"color: #000000;\">d) data<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104817cd4038684816' value='69d8b104817cd4038684816'><input type='hidden' id='bg-show-more-text-69d8b104817cd4038684816' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104817cd4038684816' value='Hide Answer'><button id='bg-showmore-action-69d8b104817cd4038684816' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104817cd4038684816' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) c\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">17. Anisha wants to develop a program to count the number of \u201cMe\u201d or \u201cMy\u201d words present in a text file \u201cSTORY.TXT\u201d .But she is not sure about the code . Help her to complete it.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">def displayMeMY(): n=0 f=open(\u201cstory.txt\u201d , \u201e____\u201f) #line 1 <\/span><\/p>\n<p><span style=\"color: #000000;\">N = __read() #line2 <\/span><\/p>\n<p><span style=\"color: #000000;\">M = N.________ #line 3 <\/span><\/p>\n<p><span style=\"color: #000000;\">for x in M : <\/span><\/p>\n<p><span style=\"color: #000000;\">if ____________________: #line 4 <\/span><\/p>\n<p><span style=\"color: #000000;\">n=n+1 f.________ #line 5 Closing the file. <\/span><\/p>\n<p><span style=\"color: #000000;\">print(\u201cCount of Me \/My words : \u201c, ____) #line 6 <\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>17.1) Which access mode to be used in line 1 to open the file .<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) w <\/span><\/p>\n<p><span style=\"color: #000000;\">b) r\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) rb <\/span><\/p>\n<p><span style=\"color: #000000;\">d) a <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104818612039604150' value='69d8b104818612039604150'><input type='hidden' id='bg-show-more-text-69d8b104818612039604150' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104818612039604150' value='Hide Answer'><button id='bg-showmore-action-69d8b104818612039604150' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104818612039604150' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) r\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>17.2) Fill the line 2 by suitable option<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) F. <\/span><\/p>\n<p><span style=\"color: #000000;\">b) f.\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) n. <\/span><\/p>\n<p><span style=\"color: #000000;\">d) N. <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104818f15067441627' value='69d8b104818f15067441627'><input type='hidden' id='bg-show-more-text-69d8b104818f15067441627' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104818f15067441627' value='Hide Answer'><button id='bg-showmore-action-69d8b104818f15067441627' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104818f15067441627' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) f.\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>17.3) Which method to be used to complete the line 3<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) readline() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) split()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) write() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) writelines() <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104819e32051049783' value='69d8b104819e32051049783'><input type='hidden' id='bg-show-more-text-69d8b104819e32051049783' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104819e32051049783' value='Hide Answer'><button id='bg-showmore-action-69d8b104819e32051049783' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104819e32051049783' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) split()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>17.4) select the correct option to complete the line 4<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) x==me or x== my <\/span><\/p>\n<p><span style=\"color: #000000;\">b) x==\u201dme\u201d or \u201cmy\u201d <\/span><\/p>\n<p><span style=\"color: #000000;\">c) x==\u201dMe\u201d or x==\u201dMy\u201d\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) x==[\u201cMe\u201d,\u201dMy\u201d] <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10481aff4070184488' value='69d8b10481aff4070184488'><input type='hidden' id='bg-show-more-text-69d8b10481aff4070184488' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10481aff4070184488' value='Hide Answer'><button id='bg-showmore-action-69d8b10481aff4070184488' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10481aff4070184488' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) x==\u201dMe\u201d or x==\u201dMy\u201d<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>17.5) Which function is used to complete line 5.<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) Exit() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) close()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) end() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) Close()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10481c135020630802' value='69d8b10481c135020630802'><input type='hidden' id='bg-show-more-text-69d8b10481c135020630802' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10481c135020630802' value='Hide Answer'><button id='bg-showmore-action-69d8b10481c135020630802' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10481c135020630802' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) close()<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">18. Rahul is trying to perform write the data to a text file. He is not sure of the commands to be used. Hence partially he could write the program . Help him to complete the program.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">file1 = open(&#8220;myfile.txt&#8221;, ____)#line1<\/span><\/p>\n<p><span style=\"color: #000000;\">L = [&#8220;This is Delhi \\n&#8221;, &#8220;This is Paris \\n&#8221;, &#8220;This is London&#8221;]<\/span><\/p>\n<p><span style=\"color: #000000;\">file1._________(L) #line2<\/span><\/p>\n<p><span style=\"color: #000000;\">file1.close()<\/span><\/p>\n<p><span style=\"color: #000000;\">file1 = open(&#8220;myfile.txt&#8221;, _____)#line3 opening file to add new data to existing file .<\/span><\/p>\n<p><span style=\"color: #000000;\"># writing newline character<\/span><\/p>\n<p><span style=\"color: #000000;\">file1.write(&#8220;\\n&#8221;)<\/span><\/p>\n<p><span style=\"color: #000000;\">file1._________(&#8220;Today&#8221;)#line4<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>18.1) Which access mode to be used in line 1 to open the file for writing on to file.<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) w\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) w+ <\/span><\/p>\n<p><span style=\"color: #000000;\">c) wr+ <\/span><\/p>\n<p><span style=\"color: #000000;\">d) a <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10481d019002683256' value='69d8b10481d019002683256'><input type='hidden' id='bg-show-more-text-69d8b10481d019002683256' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10481d019002683256' value='Hide Answer'><button id='bg-showmore-action-69d8b10481d019002683256' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10481d019002683256' ><\/span><\/p>\n<p><span style=\"color: #000000\"><strong>a) w<\/strong>\u00a0<\/span><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>18.2) Which function to be used in line 2 for writing a list to file.<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) write() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) writelines()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) writerow() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) writeline() <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10481e0d5074031653' value='69d8b10481e0d5074031653'><input type='hidden' id='bg-show-more-text-69d8b10481e0d5074031653' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10481e0d5074031653' value='Hide Answer'><button id='bg-showmore-action-69d8b10481e0d5074031653' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10481e0d5074031653' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) writelines()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>18.3) Which access mode to be used in line3 to open the file for writing new content on existing file without any data loss.<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) w <\/span><\/p>\n<p><span style=\"color: #000000;\">b) w+ <\/span><\/p>\n<p><span style=\"color: #000000;\">c) wr+ <\/span><\/p>\n<p><span style=\"color: #000000;\">d) a\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10481f2a0087233395' value='69d8b10481f2a0087233395'><input type='hidden' id='bg-show-more-text-69d8b10481f2a0087233395' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10481f2a0087233395' value='Hide Answer'><button id='bg-showmore-action-69d8b10481f2a0087233395' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10481f2a0087233395' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">d) a\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>18.4) Which function to be used in line4 for writing a list to file.<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) write()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) writelines()<\/span><\/p>\n<p><span style=\"color: #000000;\"> c) writerow() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) writeline() <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048200e5056958933' value='69d8b1048200e5056958933'><input type='hidden' id='bg-show-more-text-69d8b1048200e5056958933' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048200e5056958933' value='Hide Answer'><button id='bg-showmore-action-69d8b1048200e5056958933' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048200e5056958933' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) write()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">19) Smitha wants to copy text file \u201cSource.txt\u201d onto \u201ctarget.txt\u201d barring the lines starting with a \u201c@\u201d sign. Help her in completing the code. def filter(oldfile, newfile):<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">fin=open(oldfile,___)#line1<\/span><\/p>\n<p><span style=\"color: #000000;\">fout=open(newfile,_____)#line2<\/span><\/p>\n<p><span style=\"color: #000000;\">while True :<\/span><\/p>\n<p><span style=\"color: #000000;\">text=__________#line3<\/span><\/p>\n<p><span style=\"color: #000000;\">if len(text)==0:<\/span><\/p>\n<p><span style=\"color: #000000;\">break<\/span><\/p>\n<p><span style=\"color: #000000;\">if text[0]==\u201d@\u201d :<\/span><\/p>\n<p><span style=\"color: #000000;\">continue<\/span><\/p>\n<p><span style=\"color: #000000;\">_____.write(text)#line4<\/span><\/p>\n<p><span style=\"color: #000000;\">fin._____ #line5<\/span><\/p>\n<p><span style=\"color: #000000;\">fout._____#line6<\/span><\/p>\n<p><span style=\"color: #000000;\">filter(\u201csource.txt\u201d,\u201dtarget.txt\u201d)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>19.1) In which access mode oldfile to be opened. Complete the line 1 by selecting appropriate option.<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) w <\/span><\/p>\n<p><span style=\"color: #000000;\">b) r\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) rb <\/span><\/p>\n<p><span style=\"color: #000000;\">d) a <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104820f31041482571' value='69d8b104820f31041482571'><input type='hidden' id='bg-show-more-text-69d8b104820f31041482571' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104820f31041482571' value='Hide Answer'><button id='bg-showmore-action-69d8b104820f31041482571' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104820f31041482571' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) r\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>19.2) In which access mode newfile to be opened. Complete the line 2 by selecting appropriate option.<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) w\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) r <\/span><\/p>\n<p><span style=\"color: #000000;\">c) rb <\/span><\/p>\n<p><span style=\"color: #000000;\">d) a <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104821ea7031892081' value='69d8b104821ea7031892081'><input type='hidden' id='bg-show-more-text-69d8b104821ea7031892081' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104821ea7031892081' value='Hide Answer'><button id='bg-showmore-action-69d8b104821ea7031892081' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104821ea7031892081' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) w\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">19.3) Which of the following function can be used to complete line3 for reading line by line.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) fin.readline()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) fin.readlines()<\/span><\/p>\n<p><span style=\"color: #000000;\">c)fin.read() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) fout.readline()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104822ff1071128201' value='69d8b104822ff1071128201'><input type='hidden' id='bg-show-more-text-69d8b104822ff1071128201' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104822ff1071128201' value='Hide Answer'><button id='bg-showmore-action-69d8b104822ff1071128201' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104822ff1071128201' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) fin.readline()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">19.4) Identify the object that can be used in line4<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) fin <\/span><\/p>\n<p><span style=\"color: #000000;\">b) fout\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) Fin <\/span><\/p>\n<p><span style=\"color: #000000;\">d) Fout<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104824230034192891' value='69d8b104824230034192891'><input type='hidden' id='bg-show-more-text-69d8b104824230034192891' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104824230034192891' value='Hide Answer'><button id='bg-showmore-action-69d8b104824230034192891' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104824230034192891' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) fout\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">19.5) Identify the function that can be used in line5 and 6 to close the files<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) closed() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) close()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) end() <\/span><\/p>\n<p><span style=\"color: #000000;\">d)eol()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048252a1024244617' value='69d8b1048252a1024244617'><input type='hidden' id='bg-show-more-text-69d8b1048252a1024244617' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048252a1024244617' value='Hide Answer'><button id='bg-showmore-action-69d8b1048252a1024244617' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048252a1024244617' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) close()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">20. Write the output of the following code<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">f = open(&#8220;data.txt&#8221;, &#8220;r&#8221;)<\/span><\/p>\n<p><span style=\"color: #000000;\">d =read()<\/span><\/p>\n<p><span style=\"color: #000000;\">d1 = read(5)<\/span><\/p>\n<p><span style=\"color: #000000;\">print(d)<\/span><\/p>\n<p><span style=\"color: #000000;\">print(d1)<\/span><\/p>\n<p><span style=\"color: #000000;\">#data file contains the following data<\/span><\/p>\n<p><span style=\"color: #000000;\">Welcome to python program<\/span><\/p>\n<p><span style=\"color: #000000;\">a) Welcome to python program<\/span><\/p>\n<p><span style=\"color: #000000;\">b) Welco<\/span><\/p>\n<p><span style=\"color: #000000;\">c) error\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) None<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104826175078408350' value='69d8b104826175078408350'><input type='hidden' id='bg-show-more-text-69d8b104826175078408350' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104826175078408350' value='Hide Answer'><button id='bg-showmore-action-69d8b104826175078408350' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104826175078408350' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) error\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">21. Your teacher has given you a method\/function FilterWords() in python which reads data from a text file NewsLetter.TXT. Your teachers intentionally kept few blanks in between the code and asked you to fill the blanks so that the code will run to find desired result. Do the needful with the following python code.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">def FilterWords():<\/span><\/p>\n<p><span style=\"color: #000000;\">c=0<\/span><\/p>\n<p><span style=\"color: #000000;\">file=open(&#8216;NewsLetter.TXT&#8217;, &#8216;_____&#8217;) #Statement-1<\/span><\/p>\n<p><span style=\"color: #000000;\">data = file._____ #Statement-2<\/span><\/p>\n<p><span style=\"color: #000000;\">line = _____ #Statement-3<\/span><\/p>\n<p><span style=\"color: #000000;\">linecount= _____: #Statement-4<\/span><\/p>\n<p><span style=\"color: #000000;\">print(\u201cNo of lines\u201d,linecount)<\/span><\/p>\n<p><span style=\"color: #000000;\">_________ #Statement-5<\/span><\/p>\n<p><span style=\"color: #000000;\">FilterWords()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">21.1) Fill in the statement 1 with appropriate access mode<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) rb <\/span><\/p>\n<p><span style=\"color: #000000;\">b) r\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) w <\/span><\/p>\n<p><span style=\"color: #000000;\">d)a<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104826c10013594761' value='69d8b104826c10013594761'><input type='hidden' id='bg-show-more-text-69d8b104826c10013594761' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104826c10013594761' value='Hide Answer'><button id='bg-showmore-action-69d8b104826c10013594761' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104826c10013594761' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) r\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">21.2) Fill the statement 2 with appropriate function to read 5 characters<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) read() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) read(5)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) readline(5) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) get(5)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104827a10000099794' value='69d8b104827a10000099794'><input type='hidden' id='bg-show-more-text-69d8b104827a10000099794' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104827a10000099794' value='Hide Answer'><button id='bg-showmore-action-69d8b104827a10000099794' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104827a10000099794' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) read(5)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">21.3) Fill the statement 3 to read the remaining content of the file in list form.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) file.read() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) file.readlines()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) file.readline() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) readlines()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048288f3094672270' value='69d8b1048288f3094672270'><input type='hidden' id='bg-show-more-text-69d8b1048288f3094672270' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048288f3094672270' value='Hide Answer'><button id='bg-showmore-action-69d8b1048288f3094672270' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048288f3094672270' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) file.readlines()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">21.4) Fill the statement 4 to count the no. of lines in the file.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) len() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) len(line)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) Len(line) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) len.line<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104829750033263204' value='69d8b104829750033263204'><input type='hidden' id='bg-show-more-text-69d8b104829750033263204' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104829750033263204' value='Hide Answer'><button id='bg-showmore-action-69d8b104829750033263204' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104829750033263204' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) len(line)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">21.5) Fill in the blank in Statement-5 to close the file.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) file.close()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) File.Close() <\/span><\/p>\n<p><span style=\"color: #000000;\">c) Close() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) end()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10482a7b1054124319' value='69d8b10482a7b1054124319'><input type='hidden' id='bg-show-more-text-69d8b10482a7b1054124319' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10482a7b1054124319' value='Hide Answer'><button id='bg-showmore-action-69d8b10482a7b1054124319' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10482a7b1054124319' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) file.close()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">22. Renu wants to write multiple lines i.e 5 lines of text content into a text file mylife.txt.But she is not able to do it. Help her to complete the program.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">F =open( ___________) #line 1<\/span><\/p>\n<p><span style=\"color: #000000;\">________________ #line 2<\/span><\/p>\n<p><span style=\"color: #000000;\">Line = ____________________#line 3<\/span><\/p>\n<p><span style=\"color: #000000;\">_____________ #line 4<\/span><\/p>\n<p><span style=\"color: #000000;\">_____________ #line 5<\/span><\/p>\n<p><span style=\"color: #000000;\">f.close()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">22.1) Fill line 1 with correct statement.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) (\u201cmylife.txt\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">b) (\u201cmylife.txt\u201d,\u201dw\u201d)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) (\u201cmylife.txt\u201d, \u201c wb\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) (mylife.txt)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10482b6b8034094186' value='69d8b10482b6b8034094186'><input type='hidden' id='bg-show-more-text-69d8b10482b6b8034094186' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10482b6b8034094186' value='Hide Answer'><button id='bg-showmore-action-69d8b10482b6b8034094186' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10482b6b8034094186' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) (\u201cmylife.txt\u201d,\u201dw\u201d)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">22.2) Choose the correct option for looping to fill line2<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) For I in range(5): <\/span><\/p>\n<p><span style=\"color: #000000;\">b) for I in range(1,5): <\/span><\/p>\n<p><span style=\"color: #000000;\">c) for I in range(5):\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) for I in range(5)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10482c527059326243' value='69d8b10482c527059326243'><input type='hidden' id='bg-show-more-text-69d8b10482c527059326243' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10482c527059326243' value='Hide Answer'><button id='bg-showmore-action-69d8b10482c527059326243' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10482c527059326243' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) for I in range(5):\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">22.3) Fill line 3 with correct option to take the input from console IO.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) Input(\u201center a line\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">b) input(\u201center a line\u201d)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) str(\u201cEnter a line\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) int(input((\u201center a line\u201d) )<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10482d5d6065436914' value='69d8b10482d5d6065436914'><input type='hidden' id='bg-show-more-text-69d8b10482d5d6065436914' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10482d5d6065436914' value='Hide Answer'><button id='bg-showmore-action-69d8b10482d5d6065436914' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10482d5d6065436914' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) input(\u201center a line\u201d)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">22.4) Fill line 4 with correct option to copy the line to file.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) write(Line) <\/span><\/p>\n<p><span style=\"color: #000000;\">b) writeline(Line) <\/span><\/p>\n<p><span style=\"color: #000000;\">c) F.write(\u201cLine\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) F.write(Line)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10482e516048198777' value='69d8b10482e516048198777'><input type='hidden' id='bg-show-more-text-69d8b10482e516048198777' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10482e516048198777' value='Hide Answer'><button id='bg-showmore-action-69d8b10482e516048198777' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10482e516048198777' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">d) F.write(Line)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">22.5) Fill line 5 with correct option to add new line character after every line.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) write(\u201c \u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">b) writeline(\u201c \u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">c) F.write(\u201c\\n\u201d)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) write(\u201c\\n\u201d)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10482f059049397574' value='69d8b10482f059049397574'><input type='hidden' id='bg-show-more-text-69d8b10482f059049397574' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10482f059049397574' value='Hide Answer'><button id='bg-showmore-action-69d8b10482f059049397574' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10482f059049397574' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) F.write(\u201c\\n\u201d)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>23. Sonu wants to create one single program to read and write data using a single file object.But she got confused and could not complete the program. Help her to complete it .<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">fileobject=open(&#8220;report.txt&#8221;, \u201c____\u201d) # line 1<\/span><\/p>\n<p><span style=\"color: #000000;\">print (&#8220;WRITING DATA IN THE FILE&#8221;)<\/span><\/p>\n<p><span style=\"color: #000000;\">print() # to display a blank line<\/span><\/p>\n<p><span style=\"color: #000000;\">while True:<\/span><\/p>\n<p><span style=\"color: #000000;\">line= input(&#8220;Enter a sentence &#8220;)<\/span><\/p>\n<p><span style=\"color: #000000;\">fileobject.___________ #line2<\/span><\/p>\n<p><span style=\"color: #000000;\">fileobject.write(&#8216;\\n&#8217;)<\/span><\/p>\n<p><span style=\"color: #000000;\">choice=input(&#8220;Do you wish to enter more data? (y\/n): &#8220;)<\/span><\/p>\n<p><span style=\"color: #000000;\">if choice in (&#8216;n&#8217;,&#8217;N&#8217;):<\/span><\/p>\n<p><span style=\"color: #000000;\">break<\/span><\/p>\n<p><span style=\"color: #000000;\">print(&#8220;The byte position of file object is &#8220;,fileobject.tell())<\/span><\/p>\n<p><span style=\"color: #000000;\">fileobject._________ # line3<\/span><\/p>\n<p><span style=\"color: #000000;\">print()<\/span><\/p>\n<p><span style=\"color: #000000;\">print(&#8220;READING DATA FROM THE FILE&#8221;)<\/span><\/p>\n<p><span style=\"color: #000000;\">str=_______________ #line4<\/span><\/p>\n<p><span style=\"color: #000000;\">print(str)<\/span><\/p>\n<p><span style=\"color: #000000;\">___________ #line 5<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">23.1) Fill the line1 with appropriate access mode to perform both write and read operations.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) r+ <\/span><\/p>\n<p><span style=\"color: #000000;\">b) w <\/span><\/p>\n<p><span style=\"color: #000000;\">c) w+\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) a<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10482f982001536333' value='69d8b10482f982001536333'><input type='hidden' id='bg-show-more-text-69d8b10482f982001536333' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10482f982001536333' value='Hide Answer'><button id='bg-showmore-action-69d8b10482f982001536333' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10482f982001536333' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) w+\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">23.2) Fill Line 2 to perform write operation on to the file .<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) Writeline(line) <\/span><\/p>\n<p><span style=\"color: #000000;\">b) write(line)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) writelines(line) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) writerow(line)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048302a8045140549' value='69d8b1048302a8045140549'><input type='hidden' id='bg-show-more-text-69d8b1048302a8045140549' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048302a8045140549' value='Hide Answer'><button id='bg-showmore-action-69d8b1048302a8045140549' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048302a8045140549' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) write(line)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">23.3) Fill line 3 with correct function that places file object at beginning of file<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) tell() <\/span><\/p>\n<p><span style=\"color: #000000;\">b) seek(0)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) Seek(0) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) seek()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104830b93084981919' value='69d8b104830b93084981919'><input type='hidden' id='bg-show-more-text-69d8b104830b93084981919' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104830b93084981919' value='Hide Answer'><button id='bg-showmore-action-69d8b104830b93084981919' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104830b93084981919' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) seek(0)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">23.4) Fill line 4 to read to all the content of the file.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) fileobject.read()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) read() <\/span><\/p>\n<p><span style=\"color: #000000;\">c) fileobject.readline() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) readrow()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104831488034819337' value='69d8b104831488034819337'><input type='hidden' id='bg-show-more-text-69d8b104831488034819337' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104831488034819337' value='Hide Answer'><button id='bg-showmore-action-69d8b104831488034819337' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104831488034819337' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) fileobject.read()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">23.5) Fill line 5 to close the file.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) fileobject.close()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) Fileobject.Close() <\/span><\/p>\n<p><span style=\"color: #000000;\">c) Close() <\/span><\/p>\n<p><span style=\"color: #000000;\">d) end()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104831dc1058899607' value='69d8b104831dc1058899607'><input type='hidden' id='bg-show-more-text-69d8b104831dc1058899607' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104831dc1058899607' value='Hide Answer'><button id='bg-showmore-action-69d8b104831dc1058899607' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104831dc1058899607' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) fileobject.close()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p><strong><span style=\"color: #000000;\">24. Mr.Ravi, has written code which reads each character of a text file story.txt,and also counts and displays the occurance of alphabets of A (include small cases \u201ea\u201f too).But while doing so ,he is unable to complete the code ,help him to complete the code.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">Ex : If the file content is as follows:<\/span><\/p>\n<p><span style=\"color: #000000;\">Updated information<\/span><\/p>\n<p><span style=\"color: #000000;\">As simplified by official websites.<\/span><\/p>\n<p><span style=\"color: #000000;\">The function EUcount() will display the output as :<\/span><\/p>\n<p><span style=\"color: #000000;\">A or a :4<\/span><\/p>\n<p><span style=\"color: #000000;\">M or m : 2<\/span><\/p>\n<p><span style=\"color: #000000;\">Code :<\/span><\/p>\n<p><span style=\"color: #000000;\">def EUcount():<\/span><\/p>\n<p><span style=\"color: #000000;\">________________ #1 statement to open the file<\/span><\/p>\n<p><span style=\"color: #000000;\">A=0<\/span><\/p>\n<p><span style=\"color: #000000;\">_________________ #2 statement to read the data from the file<\/span><\/p>\n<p><span style=\"color: #000000;\">for x in r:<\/span><\/p>\n<p><span style=\"color: #000000;\">_________________# 3 statement<\/span><\/p>\n<p><span style=\"color: #000000;\">A=A+1<\/span><\/p>\n<p><span style=\"color: #000000;\">42<\/span><\/p>\n<p><span style=\"color: #000000;\">f.close()<\/span><\/p>\n<p><span style=\"color: #000000;\">print(\u201cA or a:\u201d,A)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">24.1) Which of the following commands is used to open the file \u201cStory.txt\u201d? (marked as #1 in the Python code)<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) f= open(&#8220;story.txt&#8221;,&#8217;w&#8217;)<\/span><\/p>\n<p><span style=\"color: #000000;\">b) f= open (&#8220;story.txt &#8220;,&#8217;r&#8217;)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) f= open (&#8220;story.txt &#8220;,&#8217;r+&#8217;)<\/span><\/p>\n<p><span style=\"color: #000000;\">d) f= open (&#8220;story.txt &#8220;,&#8217;rb&#8217;)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048326d2090059015' value='69d8b1048326d2090059015'><input type='hidden' id='bg-show-more-text-69d8b1048326d2090059015' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048326d2090059015' value='Hide Answer'><button id='bg-showmore-action-69d8b1048326d2090059015' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048326d2090059015' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) f= open (&#8220;story.txt &#8220;,&#8217;r&#8217;)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">24.2)Which of the following commands is used to read the data from the file, Story.txt? (marked as #2 in the Python code)<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) f.read( 20)<\/span><\/p>\n<p><span style=\"color: #000000;\">b) f.read()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) f.write(L,F)<\/span><\/p>\n<p><span style=\"color: #000000;\">d) f=pickle.dump(L)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104833038011790704' value='69d8b104833038011790704'><input type='hidden' id='bg-show-more-text-69d8b104833038011790704' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104833038011790704' value='Hide Answer'><button id='bg-showmore-action-69d8b104833038011790704' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104833038011790704' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) f.read()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">24.3)Which of the following commands is used to compare alphabets of A (include small cases &#8220;a&#8221; too).<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) if x==\u201fA\u201f or x==\u201da\u201d:\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) if x==\u201fA\u201f or \u201da\u201d: <\/span><\/p>\n<p><span style=\"color: #000000;\">c) if x=\u201fA\u201f or x=\u201da\u201d: <\/span><\/p>\n<p><span style=\"color: #000000;\">d) if x in \u201fA\u201f or \u201da\u201d:<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104833935010716843' value='69d8b104833935010716843'><input type='hidden' id='bg-show-more-text-69d8b104833935010716843' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104833935010716843' value='Hide Answer'><button id='bg-showmore-action-69d8b104833935010716843' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104833935010716843' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) if x==\u201fA\u201f or x==\u201da\u201d:\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<h3><span style=\"color: #000000;\">MCQ Seek and tell methods, manipulation of data in a text file<\/span><\/h3>\n<p><strong><span style=\"color: #000000;\">25. Which function is used to change the position of the File Handle to a given specific position.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) seek()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) read()<\/span><\/p>\n<p><span style=\"color: #000000;\">c) tail()<\/span><\/p>\n<p><span style=\"color: #000000;\">d) write()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104834239004794627' value='69d8b104834239004794627'><input type='hidden' id='bg-show-more-text-69d8b104834239004794627' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104834239004794627' value='Hide Answer'><button id='bg-showmore-action-69d8b104834239004794627' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104834239004794627' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) seek()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">26. Seek() function with negative offset only works when file is opened in &#8212;&#8212;&#8211; mode.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) read mode<\/span><\/p>\n<p><span style=\"color: #000000;\">b) write mode<\/span><\/p>\n<p><span style=\"color: #000000;\">c) binary mode\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) All of these<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104834b36094169074' value='69d8b104834b36094169074'><input type='hidden' id='bg-show-more-text-69d8b104834b36094169074' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104834b36094169074' value='Hide Answer'><button id='bg-showmore-action-69d8b104834b36094169074' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104834b36094169074' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) binary mode<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">27. What is the use of seek() method in files?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) sets the file\u201fs current position at the offset<\/span><\/p>\n<p><span style=\"color: #000000;\">b) sets the file\u201fs previous position at the offset<\/span><\/p>\n<p><span style=\"color: #000000;\">c) sets the file\u201fs current position within the file<\/span><\/p>\n<p><span style=\"color: #000000;\">d) none of the mentioned<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104835436080022110' value='69d8b104835436080022110'><input type='hidden' id='bg-show-more-text-69d8b104835436080022110' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104835436080022110' value='Hide Answer'><button id='bg-showmore-action-69d8b104835436080022110' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104835436080022110' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) sets the file\u201fs current position at the offset<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">28. How do you get the current position within the file?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) fp.seek()<\/span><\/p>\n<p><span style=\"color: #000000;\">b) fp.tell()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) fp.loc<\/span><\/p>\n<p><span style=\"color: #000000;\">d) fp.pos<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104835d30081099457' value='69d8b104835d30081099457'><input type='hidden' id='bg-show-more-text-69d8b104835d30081099457' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104835d30081099457' value='Hide Answer'><button id='bg-showmore-action-69d8b104835d30081099457' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104835d30081099457' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) fp.tell()\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">29. How do you change the file position to an offset value from the start?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) fp.seek(offset, 0)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) fp.seek(offset, 1)<\/span><\/p>\n<p><span style=\"color: #000000;\">c) fp.seek(offset, 2)<\/span><\/p>\n<p><span style=\"color: #000000;\">d) none of the mentioned<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104836659084777174' value='69d8b104836659084777174'><input type='hidden' id='bg-show-more-text-69d8b104836659084777174' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104836659084777174' value='Hide Answer'><button id='bg-showmore-action-69d8b104836659084777174' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104836659084777174' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) fp.seek(offset, 0)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">30. What happens if no arguments are passed to the seek function?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) file position is set to the start of file<\/span><\/p>\n<p><span style=\"color: #000000;\">b) file position is set to the end of file<\/span><\/p>\n<p><span style=\"color: #000000;\">c) file position remains unchanged<\/span><\/p>\n<p><span style=\"color: #000000;\">d) error\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104837612011682085' value='69d8b104837612011682085'><input type='hidden' id='bg-show-more-text-69d8b104837612011682085' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104837612011682085' value='Hide Answer'><button id='bg-showmore-action-69d8b104837612011682085' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104837612011682085' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">d) error\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">31. If we open the file in read mode then the initial value of tell() is<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) -1\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) 0\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) 1<\/span><\/p>\n<p><span style=\"color: #000000;\">d) End of the file<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b1048384c0060755566' value='69d8b1048384c0060755566'><input type='hidden' id='bg-show-more-text-69d8b1048384c0060755566' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b1048384c0060755566' value='Hide Answer'><button id='bg-showmore-action-69d8b1048384c0060755566' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b1048384c0060755566' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) -1\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">32. How many arguments passed to the tell()?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) 0\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) 1<\/span><\/p>\n<p><span style=\"color: #000000;\">c) 2<\/span><\/p>\n<p><span style=\"color: #000000;\">d) variable number of arguments<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104839310022121131' value='69d8b104839310022121131'><input type='hidden' id='bg-show-more-text-69d8b104839310022121131' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104839310022121131' value='Hide Answer'><button id='bg-showmore-action-69d8b104839310022121131' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104839310022121131' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) 0\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">33. Which is the correct statement with respect of seek() function?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) 0: sets the reference point at the beginning of the file<\/span><\/p>\n<p><span style=\"color: #000000;\">b) 1: sets the reference point at the current file position<\/span><\/p>\n<p><span style=\"color: #000000;\">c) 2: sets the reference point at the end of the file<\/span><\/p>\n<p><span style=\"color: #000000;\">d) All of these\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104839e57056636738' value='69d8b104839e57056636738'><input type='hidden' id='bg-show-more-text-69d8b104839e57056636738' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104839e57056636738' value='Hide Answer'><button id='bg-showmore-action-69d8b104839e57056636738' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104839e57056636738' ><\/span><\/p>\n<p><span style=\"color: #000000\"><strong>d) All of these\u00a0<\/strong>\u00a0<\/span><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">34. What is the use of seek() method in files()?<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) sets the file&#8217;s current position at the offset\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) sets the file&#8217;s previous position at the offset <\/span><\/p>\n<p><span style=\"color: #000000;\">c) sets the file&#8217;s current position within the file <\/span><\/p>\n<p><span style=\"color: #000000;\">d) none of the mentioned<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483a799095074209' value='69d8b10483a799095074209'><input type='hidden' id='bg-show-more-text-69d8b10483a799095074209' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483a799095074209' value='Hide Answer'><button id='bg-showmore-action-69d8b10483a799095074209' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483a799095074209' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) sets the file&#8217;s current position at the offset\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>35. Which of the following statements correctly explain the function of tell() method?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) tells the current position within the file.\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) indicates that the next read or write will occur at that many bytes from the beginning of the file.<\/span><\/p>\n<p><span style=\"color: #000000;\">c) move the current file position to a different location. <\/span><\/p>\n<p><span style=\"color: #000000;\">d) it changes the file position only if allowed to do so else returns an error. <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483b0e7087242285' value='69d8b10483b0e7087242285'><input type='hidden' id='bg-show-more-text-69d8b10483b0e7087242285' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483b0e7087242285' value='Hide Answer'><button id='bg-showmore-action-69d8b10483b0e7087242285' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483b0e7087242285' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) tells the current position within the file.\u00a0<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #000000\">b) indicates that the next read or write will occur at that many bytes from the beginning of the file.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>36. Which of the following statements correctly explain the function of seek() method?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) tell the current position within the file. <\/span><\/p>\n<p><span style=\"color: #000000;\">b) indicate that the next read or write occurs from that position in a file. <\/span><\/p>\n<p><span style=\"color: #000000;\">c) determine if you can move the file position or not. <\/span><\/p>\n<p><span style=\"color: #000000;\">d) move the current file position to a different location at a defined offset.\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483bc59032033806' value='69d8b10483bc59032033806'><input type='hidden' id='bg-show-more-text-69d8b10483bc59032033806' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483bc59032033806' value='Hide Answer'><button id='bg-showmore-action-69d8b10483bc59032033806' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483bc59032033806' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">d) move the current file position to a different location at a defined offset.<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\"><\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>37. Which of the following command is used to open a file \u201cc:\\temp.txt\u201d in read-mode only?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) infile = open(\u201cc:\\temp.txt\u201d, \u201cr\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">b) infile = open(\u201cc:\\\\temp.txt\u201d, \u201cr\u201d)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) infile = open(file = \u201cc:\\temp.txt\u201d, \u201cr+\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) infile = open(file = \u201cc:\\\\temp.txt\u201d, \u201cr+\u201d)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483c563025712454' value='69d8b10483c563025712454'><input type='hidden' id='bg-show-more-text-69d8b10483c563025712454' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483c563025712454' value='Hide Answer'><button id='bg-showmore-action-69d8b10483c563025712454' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483c563025712454' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) infile = open(\u201cc:\\\\temp.txt\u201d, \u201cr\u201d)<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">38. To read the next line of the file from a file object fobj, we use:<\/span><\/strong><\/p>\n<p><span style=\"color: #000000;\">a) fobj.read(2)<\/span><\/p>\n<p><span style=\"color: #000000;\">b) fobj.read()<\/span><\/p>\n<p><span style=\"color: #000000;\">c) fobj.readline()\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) fobj.readlines()<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483d090020571180' value='69d8b10483d090020571180'><input type='hidden' id='bg-show-more-text-69d8b10483d090020571180' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483d090020571180' value='Hide Answer'><button id='bg-showmore-action-69d8b10483d090020571180' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483d090020571180' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) fobj.readline()<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>39. What happens if no arguments are passed to the seek function?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) file position is set to the start of file <\/span><\/p>\n<p><span style=\"color: #000000;\">b) file position is set to the end of file<\/span><\/p>\n<p><span style=\"color: #000000;\">c) file position remains unchanged <\/span><\/p>\n<p><span style=\"color: #000000;\">d) error\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483d9d2018388612' value='69d8b10483d9d2018388612'><input type='hidden' id='bg-show-more-text-69d8b10483d9d2018388612' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483d9d2018388612' value='Hide Answer'><button id='bg-showmore-action-69d8b10483d9d2018388612' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483d9d2018388612' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">d) error<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>40. What does the &lt;readlines()&gt; method returns?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) str <\/span><\/p>\n<p><span style=\"color: #000000;\">b) a list of lines\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">c) list of single characters <\/span><\/p>\n<p><span style=\"color: #000000;\">d) list of integers <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483e2d7024517395' value='69d8b10483e2d7024517395'><input type='hidden' id='bg-show-more-text-69d8b10483e2d7024517395' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483e2d7024517395' value='Hide Answer'><button id='bg-showmore-action-69d8b10483e2d7024517395' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483e2d7024517395' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">b) a list of lines\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>41. Which of the following command is used to open a file \u201cc:\\temp.txt\u201d in append-mode?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) outfile = open(\u201cc:\/temp.txt\u201d, \u201ca\u201d)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) outfile = open(\u201cc:\\\\temp.txt\u201d, \u201crw\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">c) outfile = open(\u201cc:\\temp.txt\u201d, \u201cw+\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) outfile = open(\u201cc:\\\\temp.txt\u201d, \u201cr+\u201d) <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483ed91030620369' value='69d8b10483ed91030620369'><input type='hidden' id='bg-show-more-text-69d8b10483ed91030620369' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483ed91030620369' value='Hide Answer'><button id='bg-showmore-action-69d8b10483ed91030620369' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483ed91030620369' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) outfile = open(\u201cc:\/temp.txt\u201d, \u201ca\u201d)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>42. Which of the following commands can be used to read \u201cn\u201d number of characters from a file using the file object &lt;file&gt;?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) file.read(n)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">b) n = file.read() <\/span><\/p>\n<p><span style=\"color: #000000;\">c) file.readline(n) <\/span><\/p>\n<p><span style=\"color: #000000;\">d) file.readlines() <\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b10483fd31069236305' value='69d8b10483fd31069236305'><input type='hidden' id='bg-show-more-text-69d8b10483fd31069236305' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b10483fd31069236305' value='Hide Answer'><button id='bg-showmore-action-69d8b10483fd31069236305' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b10483fd31069236305' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">a) file.read(n)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>43. Which of the following functions can be used to check if a file \u201clogo\u201d exists?<\/strong> <\/span><\/p>\n<p><span style=\"color: #000000;\">a) os.path.isFile(logo) <\/span><\/p>\n<p><span style=\"color: #000000;\">b) os.path.exists(logo)<\/span><\/p>\n<p><span style=\"color: #000000;\">c) os.path.isfile(logo)\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">d) os.isFile(logo)<\/span><\/p>\n<p><span style=\"color: #000000;\"><input type='hidden' bg_collapse_expand='69d8b104840ec4052358336' value='69d8b104840ec4052358336'><input type='hidden' id='bg-show-more-text-69d8b104840ec4052358336' value='Show Answer'><input type='hidden' id='bg-show-less-text-69d8b104840ec4052358336' value='Hide Answer'><button id='bg-showmore-action-69d8b104840ec4052358336' class='bg-showmore-plg-button bg-orange-button bg-arrow '   style=\" color:#4a4949;\">Show Answer<\/button><div id='bg-showmore-hidden-69d8b104840ec4052358336' ><\/span><\/p>\n<p><strong><span style=\"color: #000000\">c) os.path.isfile(logo)\u00a0<\/span><\/strong><\/p>\n<p><span style=\"color: #000000\">\u00a0<\/div><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>Don&#8217;t Miss Topics:<\/h2>\n<h3><a href=\"https:\/\/cbsepython.in\/text-file-mcq-question-bank-for-class-12\/\">50+ Most Important Text File MCQ for Term 1 (Including CASE BASED MCQ)<\/a><\/h3>\n<h3><a href=\"https:\/\/cbsepython.in\/binary-file-mcq-question-bank-for-class-12\/\">60+ Most Important Binary File MCQ for Term 1 (Including CASE BASED MCQ)<\/a><\/h3>\n<h3><a href=\"https:\/\/cbsepython.in\/csv-file-mcq-question-bank-for-class-12\/\">40+ Most Important CSV File MCQ for Term 1(Including CASE BASED MCQ)<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Must Prepare Python File Handling MCQ Class 12 for Term 1 MCQ on Writing\/appending data to a text file using write() and writelines(), Reading from a text file using read(), readline( ) and readlines() &nbsp; 1. The ____________ method returns a list containing each line of the file as a list item. a) read() b) [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,20],"tags":[],"class_list":["post-1544","post","type-post","status-publish","format-standard","hentry","category-cbse-sample-papers-class-12","category-cbse-computer-science-with-python-class-12"],"_links":{"self":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/1544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/comments?post=1544"}],"version-history":[{"count":0,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/1544\/revisions"}],"wp:attachment":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/media?parent=1544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/categories?post=1544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/tags?post=1544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}