Lab 4: Knowledge Check
These questions check your knowledge of concepts from this lab. Use the button at the bottom to show your answers once you've attempted them.
-
The operands of comparison operators like '<' should always be Boolean values.
True False -
The operands of logical operators like 'and' should normally be Boolean values.
True False -
Which of the following functions is a predicate? (pick one or more)
-
def a(): return True -
def b(x): if x < 3: return True else: return False -
def c(x): if x < 3: return True -
def d(x): return x < 3 -
def e(x): return x + 3
-
-
Given the following predicate:
...which of the following pieces of code correctly printsdef canRide(age): return age >= 8'You can ride.'whenageis at least 8, and not otherwise? (pick one or more)
-
if canRide: print('You can ride.') -
if canRide(): print('You can ride.') -
if canRide(age): print('You can ride.') -
if age >= canRide: print('You can ride.') -
if age >= canRide(age): print('You can ride.') -
if not canRide(age): pass else: print('You can ride.')
-
-
Using the same
canRidepredicate, which of the following expressions evaluates toTrue? (pick one or more)
-
not canRide(5) -
canRide(8) -
canRide(22) -
canRide(8) and canRide(22) -
canRide(5) or canRide(10) -
canRide(9) == True -
((canRide(9) == True) == True) == True
-
-
What is the result of the following expression?
3 > 5 or (2 < 3 and 'hello' > 'goodbye')
True False