Multiple choice quiz about Python - Part 3
- Question 1: What does opening file with mode 'a' mean?
- 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.
-
- 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
pass
except (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 = 1
def 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 = 1
def 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
You should read it
- Multiple choice test on Python - Part 11
- Multiple choice quiz about Python - Part 2
- Multiple choice quiz about Python - Part 10
- Multiple choice quiz about Python - Part 5
- Multiple choice quiz about Python - Part 1
- Multiple choice quiz about Python - Part 6
- Multiple choice quiz about Python - Part 8
- Multiple choice quiz about Python - Part 9
May be interested
- Multiple choice quiz about Python - Part 4continue python's thematic quiz, part 4 goes back to the topic core data type - standard data types in python. let's try with quantrimang to try the 10 questions below.
- Multiple choice quiz about Python - Part 5if you are interested in learning about the python programming language, the following quiz of network administrator will provide useful knowledge for your learning.
- What do you know about Data Mining? - Part 2how much did you know about data mining? keep testing your knowledge with quantrimang through the following multiple choice questions!
- What do you know about Data Mining? - Part 1how much did you know about data mining? try your knowledge with quantrimang through the following data mining quiz questions!
- Multiple choice quiz about Python - Part 6to help readers add to their knowledge of python's built-in functions, the network administrator will send you multiple choice questions on this topic. please try.
- Test about database security P11testing of databases will help you gain more useful knowledge about this topic to apply to learning and working. the question set will have 10 sentences to test your knowledge.