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
- eQuiz - VB.NET testing test - Part 2in the previous article, i showed you the first part of the vb.net test. and this time, we will continue with part 2 of this popular quiz series on programming languages, the whole test will have 15 questions with unlimited response time.
- eQuiz - Multiple choice test on JDBC - Part 1in the quiz below, we will introduce you to part 1 of the jdbc basic knowledge test series with 15 questions.
- eQuiz - Quiz on Core Java - Part 2in the quiz below, you will be able to try out part 2 of the series related to core java - one of the most popular programming languages today. in total, the test will have 15 questions in the form of multiple choice, with an unlimited response time ...
- JAVA P8 test quizif you are interested in learning about the java programming language, the following quiz of network administrator will provide you with a lot of useful knowledge for your learning.
- Testing of computer architecture - Part 2next to this topic, in the quiz below will be more challenging, let's start.
- What do you know about iPhone? Doing this test will be clear (part 2)do multiple-choice questions about iphone in part 1 make it difficult for you? try the next 10 questions about the iphone.
- Multiple choice questions about Photoshop - Part 1a set of multiple-choice questions about photoshop for you to try and understand.
- [QUIZ] Test your understanding of SQL - Part 5multiple-choice questions on sql help you familiarize and review useful knowledge for work and learning sql language.
- What do you know about iPhone? Doing this test will be clear (part 1)as a smartphone user, maybe also holding the iphone in your hand, what do you really know about this apple pet's baby? let's take the quiz below to answer that question.
- [QUIZ] Test your understanding of SQL - Part 4let's try our knowledge with multiple choice questions about sql database management system.