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).
Which of the following values/expressions are equivalent to True
?
0
1
2
'word'
[1,2,3]
x and False
True or x
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
==
should be used.:
is missing.False
.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.