MCQs below are intended for Python Lesson 5 Making Choices with focus on and, or, and if.
Multiple answers are possible (tested with python 2.6.6 and 2.7.8).
MCQ 1.
Which of the following values/expressions are equivalent to True?
012'word'[1,2,3]x and FalseTrue or x
MCQ 2.
Given x = 3, which of the following will print out the value of x?
-
if x = 3: print x
2.
if x == 3:
print x
3.
if x == 3:
print x
4.
if x == 3
print x
5.
if x == '3'
print x
6.
if (x==3):
print x
7.
if 3 == x:
print x
Notes on answers and distractors
- Syntax error,
==should be used. - Indentation error.
- Ok.
- Syntax error,
:is missing. - Semantic error, comparison to a string yields
False. - Ok, parentheses and white spaces are optional.
- Ok.
The main focus is on getting the syntax correct as 1,2,4 are common novice mistakes and the error message is not very descriptive although it points to the culprit. Item 5 is more subtle as it doesn’t result in an error/exception.