Multiple choice quiz about Python - Part 3

Today's topic Quantrimang wants to challenge you is about File and exception handling in Python. Let's try the following 15 questions!
  1. Question 1: What does opening file with mode 'a' mean?
    1. Opening files in read-only mode.
    2. Open the file in recording mode.
    3. Open the recording mode file at the end of the file.
    4. Open the file to read and write.
  2. Question 2: What does the code below mean?
     f = open("test.txt") 
    1. Open the test.txt file that is allowed to read and write to the file.
    2. Open test.txt file and only read file.
    3. Open the test.txt file and be allowed to overwrite the file
    4. Open the file test.txt and be allowed to write to the file.
  3. Question 3: Which code automatically closes the file when an exception occurs?
    1.   with open("test.txt", encoding = 'utf-8') as f: 
    2.  try: 
      f = open("test.txt",encoding = 'utf-8')
      finall
      f.close()
    3. There is no exact answer.
    4. Both answers are correct
  4. Question 4: Which assertion is correct about the code below?
     f = open('test.txt', 'r', encoding = 'utf-8') 
    f.read()
    1. This program reads the content of test.txt file.
    2. If test.txt is downstream, the read () function will return the new line's start symbol 'n'.
    3. You can pass an integer type parameter to read ().
    4. All of the above answers are correct.
  5. Question 5: What does the code below mean?
     os.listdir() 
    1. Print out the current working directory.
    2. Print out all folders (not files) inside the given folder.
    3. Print out all folders and files inside the given folder.
    4. Create a new folder.
  6. Question 6: Which of the following statements is correct?
    1. Exception is an error that arises when executing the program (runtime error).
    2. The syntax error is also an exception.
    3. Exceptions are used by Python to remove a block of code from the program.
    4. All of the above answers are correct.
  7. Question 7: What happens if you try to open a file that doesn't exist?
    1. Python automatically creates a new file under the name you are calling.
    2. Nothing happens because the file does not exist.
    3. Caused an exception
    4. There is no right answer
  8. Question 8: What is the result of the code below?
     number = 5.0 
    try:
    r = 10/number
    print(r)
    except:
    print("Oops! Error occurred.")
    1. Oops! Error occurred.
    2. 2.0
    3. 2.0 Oops! Error occurred.
    4. 5.0
  9. Question 9: What does the following code do?
     try: 
    # đoạn code có thể gây ra lỗi
    pass
     except (TypeError, ZeroDivisionError): 
    print("Python Quiz")
    1. Print 'Python Quiz' if an exception occurs (no matter what the exception is).
    2. Print out 'Python Quiz' if no exception occurs.
    3. Print 'Python Quiz' if one of the exceptions TypeError and ZeroDivisionError occurs.
    4. Only print 'Python Quiz' when both exceptions TypeError and ZeroDivisionError happen
  10. Question 10: Which exception occurs when it detects an error does not belong to any other category?
    1. ReferenceError
    2. SystemError
    3. RuntimeError
    4. LookupError
  11. Question 11: Which result is the output of the code below?
     def myfunc(): 
    try:
    print('Monday')
    finally:
    print('Tuesday')
    myfunc()
    1. Tuesday
    2. Monday Tuesday
    3. Tuesday Monday
    4. Monday
  12. Question 12: Which result is the output of the code below?
     try: 
    print("throw")
    except:
    print("except")
    finally:
    print("finally")
    1. finally
      throw
    2. finally
      except
    3. except
      finally
    4. throw
      finally
  13. Question 13: Which assertion is correct about the program below?
     class A: 
    def __init__(self):
    self.a = 1
    self.__b = 1
      def getY(self): 
    return self.__b

    obj = A()
    obj.a = 45
    print(obj.a)
    1. The program has an error because '__b' is a private property, not accessible from outside the class.
    2. The program runs normally and the printed result is 1.
    3. The program has an error because 'a' is a private property, not accessible from outside the class.
    4. The program runs normally and the printed result is 45.
  14. Question 14: Which assertion is correct about the program below?
     class A: 
    def __init__(self):
    self.x = 1
    self.__y = 1
      def getY(self): 
    return self.__y

    a = A()

    ax = 45
    print(ax)
    1. The program has an error because 'x' is a private property, not accessible from outside the class.
    2. The program runs normally and the printed result is 1.
    3. The program has an error because '__y' is a private property, not accessible from outside the class.
    4. The program runs normally and the printed result is 45.
  15. Question 15: What does opening file with mode 'wb' mean?
    1. Open the file to record.
    2. Open the file to read and write.
    3. Open the file to record for binary format.
    4. Open the file to read and write to binary.
3.7 ★ | 6 Vote