These MCQs are for the Python lesson on Making Choices section (http://swcarpentry.github.io/python-novice-inflammation/05-cond.html).
Question 1
Suppose we want to test for inclusion in a set, where something is "in" the set if it has property-A and one of either proprty-B or property-C (assume all are boolean values). A prototype function is below:
def func( A, B, C ):
if( A and B or C ):
return True
else:
return False
(ok, this is an 'extreme' case of an MCQ … True-False)
Question 2
What is the output from the following function when the argument, x, is 30?
def func( x ):
if( x >5 ):
print "X is greater than 5"
elif( x > 10 ):
print "X is greater than 10"
if( x > 20 ):
print "X is greater than 20"
Notes