I downloaded a preview portion of 390+ Python MCQs from Anazon, thinking reading through it would help me advance my Python skills beyond what I have learned from Harvard’s online CS50P (Python) course. I’m an experienced program looking to add a new skill to my repertoire, and while the course covered many significant aspects of Python programming, there are many other details to perfect, such as best practices, developing packages, and so on.
The book is written by Manish Dnyandeo Salunke, who claims 15 years experience in IT, but it is not clear who published it. It is obvious no one edited it, or verified the correctness of the questions, answers and explanations.
Amazon allowed me to download a sample of (I think) 57 questions. Roughly half of these were wrong, and some of the others struck me as irrelevant. The maximum allowed length for an identifier, apparently, is 79 characters. Anything over 20 characters should be considered unusual, so sufficient to say the limit is several times any useful size.
Here are my complaints … I wonder how many of the remaining 330+ questions are also wrong?
Question: What is the main difference between a .py file and a .pyc file?
.py files are source code files
.py files are bytecode files
.py files are compiled Python files
Py files are compressed archive files
(in)Correct Response: 2 SHOULD BE ‘1’
Explanation: .py files contain Python source code, while .pyc files contain bytecode
Explanation is correct but response doesn’t match the options.
Question: The process of converting source code into bytecode, which is then executed by the Python interpreter, is called ……
Compilation
Interpretation
Compilation
Execution
(in)Correct Response: 2 SHOULD BE ‘1’ (or ‘3’, since the answer is shown twice)
(their)Explanation: Python uses interpretation, not compilation, to execute code.
Actually, executing the code is achieved by interpreting the bytecode. The bytecode is obtained by compiling the source code. Ask google about Java bytecode, Python bytecode.
Question: A colleague is trying to run a Python 2 script in a Python 3 environment, and the script fails due to a syntax error in the print statement. What would be the likely cause?
Python 2 uses print as a statement
Python 2 uses print as a function
Python 2 has a different file encoding
Python 2 requires a ‘__future__’ import
(in)Correct Response: 2 SHOULD BE ‘1’
(their)Explanation: …Python 2 uses print as a statement, while Python 3 uses it as a function …
The explanation is correct but the response doesn’t match the options.
Question: What will be the result of the comparison 5!=6 in Python?
TRUE
FALSE
1
Error
Correct Response: 1
Explanation: … the result is ‘True’
Complaint: Some languages use TRUE and FALSE - ALL CAPS - Python uses a capitalised first letter only. The right version is used in the explanation, but not shown in the options.
Silly questions about the logical operators to return True only if both values are True / if one value is True, and similar questions about comparison operators. Anyone who does not know such things needs to be looking for a book/course to train them in beginner Python, rather than in preparing them for interviews.
Question: Consider a scenario where you need to check if neither ‘a’ nor ‘b’ are true in Python. Which operator would you use?
not a and not b
A and b
A or b
not(a or b)
(in)Correct Response: 1
While 1 is a correct answer, so is 4, by deMorgan’s theorem. Having two correct answers is a minor error; listing only one of them as valid is a sin against the trusting consumer.
Question: What is the result of True or False and True?
TRUE
FALSE
True and False is not allowed
Error
(in)Correct Response: 2
(their nonsense) Explanation: The operation ‘True or False and True’ will result in an error because ‘and’ has a higher precedence than ‘or’, and ‘and’ is trying to combine a Boolean ‘False’ with a non-Boolean ‘True’
If their explanation were correct, the answer should be ‘4’. ‘2’ is also wrong. The correct answer is ‘1’. ‘And’ does have higher precedence, so False and True evaluate to False. Then True or False evaluate to True.The
Question: In the context of logical operators in Python, the not operator _______ the result.
Inverts
Negates
Reverses
Complements
(their) Correct Response: 1
But ‘negates’ and ‘complements’ are also correct answers.
Question: The ______ operator is used to determine if two values are not equal in Python.
Unequal
Not equal
Inequality
Difference
(Their) Correct response: 2
Answers ‘1’, ‘2’ and ‘3’ are essentially the same thing, but none of them is really the correct answer, which should be ‘!=’.
Question: A developer wants to compare two numbers and check if they are approximately equal ( with a small threshold…)
a ==b
abs(a-b) < epsilon
a is b
a !=b
(their) Response: 2
While correct, epsilon is unavailable without preparation. It requires importing the sys module.
Question: Given a scenario where a system should notify a user if the storage space goes below 5% or above 95% ….
If storage < 5 or storage > 95:
If storage <= 5 or storage >= 95:
If storage > 5 and storage < 95:
If 5 <= storage <= 95:
(their) Response: 2
The answer should be ‘1’. The requirements accept 5% and 95% as safe conditions, only outside those values is a problem.
Question: What keyword is used in Python to make a decision?
if
else
decide
choice
This question is apparently used to determine whether the applicant attended Python classes after the first day.
Question: For loops in Python use the _____ method internally to iterate over items.
Loop
Enumerate
Range
Iterate
(their) Response: 2
(their) Explanation: For loops in pYthon use the enumerate method internally to iterate over items. Enumerate returns both the index and the value of each item in the sequence, making it useful for tracking positions in the loop.
The answer should be ‘4’, or even better, ‘__iter__’. The question is about “internally”, while ‘enumerate’, while convenient, is used sometimes but not always at the user code level.
Question: You have a list of numbers and you want to compute the sum of all positive numbers only. Which control structure can be most beneficial to achieve this?
For loop
While loop
Conditional statement
List comprehension
(their) Response: 3
(their) Explanation: …a conditional statement can be most beneficial. You can iterate through the list…
You might as easily say that a loop ( for OR while ) is most beneficial. Within the loop check for positive numbers …. Actually, my choice would have been the list comprehension, since it combines everything into a compact assembly. Of cour there needs to be an ‘if’ clause … Essentially, the question is meaningless.
Comments