Pyth,pythonon Programming Quiz – 9th Week Quiz Solution
Python Programming Quiz – 9th Week Quiz Solution

Disclaimer for News Pustak

If you require any more information or you have any problems regarding copyright or have any questions about our site’s disclaimer, please feel free to contact us by email at newspustak24@gmail.com

Disclaimer for News Pustak

All the information on the website is published in good faith and for general information and educational purpose only. News Pustak does not make any warranties about the completeness, reliability, and accuracy of this information. Any action you take upon the information you find on this website is strictly at your own risk. We will not be liable for any losses and/or damage in connection with the use of our website.
Python Programming Quiz – 9th Week Quiz Solution given in this post. The solution of the 9th-week quiz are given below:-
[1] Assume that theFile is a file object, and the operations are all valid operations (i.e., theFile is open in an appropriate mode). Now if we execute –
 .numWritten = theFile.write(‘something’)
  • (a): It tell whether theFile is open or closed
  • (b): Reads and return ‘something’
  • (c): Stores the number of characters written to theFile in a variable
  • (d): reads a single line from theFile, including the newline character
Answer: (c) Stores the number of characters written to theFile in a variable
[2] Assume that theFile is a file object, and the operations are all valid operations (i.e., theFile is open in an appropriate mode). Now if we execute –
theFile.closed 
  • (a): tells (True of False) whether theFile is closed or not
  • (b): Reads and return ‘something’
  • (c): read a single line from theFile, including the newline character
  • (d): modify the file object for theFile so that the next read will be from
Answer: (a) tells (True of False) whether theFile is closed or not
[3] Assume that theFile is a file object, and the operations are all valid operations (i.e., theFile is open in an appropriate mode). Now if we execute –

theFile.tell()
  • (a): points to the location from where next byte will be read in theFile
  • (b): tell whether theFile is open or closed
  • (c): Reads and return ‘something’
  • (d): Store the number of characters written to theFile in a variable
Answer:(a) points to the location from where next byte will be read in theFile

[4] Assume that theFile is a file object, and the operations are all valid operations (i.e., theFile is open in an appropriate mode). Now if we execute –
theFile.seek(pos,ref)
  • (a): tell whether theFile is open or closed
  • (b): Read and return at most
  • (c): Reads and return ‘something’
  • (d): Store the number of characters written to theFile in a variable
Answer: (d) Store the number of characters written to theFile in a variable
[5] Assume that theFile is a file object, and the operations are all valid operations (i.e., theFile is open in an appropriate mode). Now if we execute-
theFile.readline
  • (a): tell whether theFile is open or closed
  • (b): Read and return at most
  • (c): read a single line from theFile, including the newline character
  • (d): modify the file object for theFile so that the next read will be from
Answer: (c) read a single line from theFile, including the newline character
[6] Which of the following command is used to open a file “C:\desktop\myfile.txt”, In read-mode only?
A.file_name = open(“C:\desktop\myfile.txt”, “r”)
B.file_name = open(“C:\\desktop\myfile.txt”, “r”) 
C.file_name = open(file = “C:\desktop \myfile.txt”, “r+”)
D.file_name = open(file = “C:\desktop\myfile.txt”, “r+”)
  • (a): A
  • (b): B
  • (c): C
  • (d): D
Answer: (b)file_name = open(“C:\\desktop\myfile.txt”, “r”)
[7] What will be the output of the following given code?
with open("myfile.txt", "w") as f:
      f.write("Hello World Python Programming")
      
  with open('myfile.txt', 'r') as f:
      data = f.readlines()
      for line in data:
          words = line.split()
          print (words)
  • (a): Hello
  • (b): Hello World Python Programming
  • (c): [‘Hello’, ‘World’, Python, Programming]
  • (d): Runtime Error
Answer: (c) [‘Hello’, ‘World’, Python, Programming]

[8] Which of the following commands can be used to read the entire contents of a file object (object name myfile)?
  • (a): myfile.read(n)
  • (b): myfile.read()
  • (c): myfile.readline()
  • (d): myfile.readlines()
Answer: (b)  myfile.read()
Also, see: All NCERT Books - NEWS PUSTAK

[9] The readlines() method returns ____________
  • (a): str
  • (b): a list of lines
  • (c): a list of single characters
  • (d): a list of integers
Answer: (b) a list of lines
[10] To read the remaining lines of the file from a file object infile, we use ____________
  • (a): infile.read(2)
  • (b): infile.read()
  • (c): infile.readline()
  • (d): infile.readlines()
Answer: (c)  infile.readline()
[11] When will the else part of try-except-else be executed?
  • (a): always
  • (b): when an exception occurs
  • (c): when no exception occurs
  • (d): when an exception occurs in to except block
Answer: (c) when no exception occurs
[12] What will be output when ‘1’ == 1 is executed?
  • (a): True
  • (b): False
  • (c): TypeError
  • (d): ValueError
Answer: (b) False
[13] How many except statements can a try-except block have?
  • (a): zero
  • (b): one
  • (c): more than one
  • (d): more than zero
Answer: (d) more than zero
[14] What will be the output of the following Python code?
def test():
    try:
        print(1)
    finally:
        print(2)

test()
  • (a): 1 2
  • (b): 1
  • (c): 2
  • (d): None of these
Answer: (a) 1 2
[15]  what kind of exception will be raised by (using python 3.X version)
assert 5/0 > 0
  • (a): valueError exception
  • (b): AssertionError exception
  • (c): ZeroDivisionError exception
  • (d): No exception is raised by the program
Answer: (b) AssertionError exception
Quiz 10 Solution Link update here next week stay connected -
 Week 10 Solurions

Previous Post Next Post