-
Opening files in read-only mode.
-
Open the file in recording mode.
-
Open the recording mode file at the end of the file.
-
Open the file to read and write.
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!
-
Question 1: What does opening file with mode 'a' mean?
-
Question 2: What does the code below mean?
f = open("test.txt")-
Open the test.txt file that is allowed to read and write to the file.
-
Open test.txt file and only read file.
-
Open the test.txt file and be allowed to overwrite the file
-
Open the file test.txt and be allowed to write to the file.
-
-
Question 3: Which code automatically closes the file when an exception occurs?
-
with open("test.txt", encoding = 'utf-8') as f: -
try:
f = open("test.txt",encoding = 'utf-8')
finall
f.close() -
There is no exact answer.
-
Both answers are correct
-
-
Question 4: Which assertion is correct about the code below?
f = open('test.txt', 'r', encoding = 'utf-8')
f.read()-
This program reads the content of test.txt file.
-
If test.txt is downstream, the read () function will return the new line's start symbol 'n'.
-
You can pass an integer type parameter to read ().
-
All of the above answers are correct.
-
-
Question 5: What does the code below mean?
os.listdir()-
Print out the current working directory.
-
Print out all folders (not files) inside the given folder.
-
Print out all folders and files inside the given folder.
-
Create a new folder.
-
-
Question 6: Which of the following statements is correct?
-
Exception is an error that arises when executing the program (runtime error).
-
The syntax error is also an exception.
-
Exceptions are used by Python to remove a block of code from the program.
-
All of the above answers are correct.
-
-
Question 7: What happens if you try to open a file that doesn't exist?
-
Python automatically creates a new file under the name you are calling.
-
Nothing happens because the file does not exist.
-
Caused an exception
-
There is no right answer
-
-
Question 8: What is the result of the code below?
number = 5.0
try:
r = 10/number
print(r)
except:
print("Oops! Error occurred.")-
Oops! Error occurred.
-
2.0
-
2.0 Oops! Error occurred.
-
5.0
-
-
Question 9: What does the following code do?
try:
# đoạn code có thể gây ra lỗi
passexcept (TypeError, ZeroDivisionError):
print("Python Quiz")-
Print 'Python Quiz' if an exception occurs (no matter what the exception is).
-
Print out 'Python Quiz' if no exception occurs.
-
Print 'Python Quiz' if one of the exceptions TypeError and ZeroDivisionError occurs.
-
Only print 'Python Quiz' when both exceptions TypeError and ZeroDivisionError happen
-
-
Question 10: Which exception occurs when it detects an error does not belong to any other category?
-
ReferenceError
-
SystemError
-
RuntimeError
-
LookupError
-
-
Question 11: Which result is the output of the code below?
def myfunc():
try:
print('Monday')
finally:
print('Tuesday')
myfunc()-
Tuesday
-
Monday Tuesday
-
Tuesday Monday
-
Monday
-
-
Question 12: Which result is the output of the code below?
try:
print("throw")
except:
print("except")
finally:
print("finally")-
finally
throw -
finally
except -
except
finally -
throw
finally
-
-
Question 13: Which assertion is correct about the program below?
class A:
def __init__(self):
self.a = 1
self.__b = 1def getY(self):
return self.__b
obj = A()
obj.a = 45
print(obj.a)-
The program has an error because '__b' is a private property, not accessible from outside the class.
-
The program runs normally and the printed result is 1.
-
The program has an error because 'a' is a private property, not accessible from outside the class.
-
The program runs normally and the printed result is 45.
-
-
Question 14: Which assertion is correct about the program below?
class A:
def __init__(self):
self.x = 1
self.__y = 1def getY(self):
return self.__y
a = A()
ax = 45
print(ax)-
The program has an error because 'x' is a private property, not accessible from outside the class.
-
The program runs normally and the printed result is 1.
-
The program has an error because '__y' is a private property, not accessible from outside the class.
-
The program runs normally and the printed result is 45.
-
-
Question 15: What does opening file with mode 'wb' mean?
-
Open the file to record.
-
Open the file to read and write.
-
Open the file to record for binary format.
-
Open the file to read and write to binary.
-
3.7 ★ | 6 Vote
Read More
- Multiple choice quiz about Python - Part 4
- Multiple choice quiz about Python - Part 8
- Multiple choice quiz about Python - Part 1
- Multiple choice quiz about Python - Part 7
- Multiple choice quiz about Python - Part 10
- Multiple choice test on Python - Part 11
- Multiple choice quiz about Python - Part 9
- Multiple choice quiz about Python - Part 5
- eQuiz - VB.NET testing test - Part 2
- Multiple choice test on if else and loops in Python
- eQuiz - Multiple choice test on JDBC - Part 1
- eQuiz - Quiz on Core Java - Part 2
- This is how to create multiple-choice question slides in Canva.
- JAVA P8 test quiz