Reviewed Basic datatypes LO.
Objective Questions
-------------------
.. A mininum of 8 questions here (along with answers)
1. Given a variable ``time``, print ``Good Morning`` if it is less
than 12, otherwise ``Hello``.
Answer::
if time < 12:
print "Good Morning"
else:
print "Hello"
#. Every ``if`` block must be followed by an ``else`` block. T or F?
Answer: F
#. Every ``if/elif/else`` ladder MUST end with an ``else`` block. T/F?
Answer: F
#. An if/elif/else ladder can have any number of elif blocks. T or F?
Answer: T
#. What will be printed at the end this code block::
x = 20
if x > 10:
print x * 100
Answer: IndentationError - Expected and indented block..
#. What will be printed at the end this code block::
x = 20
if x > 10:
print x * 100
else:
print x
Answer: SyntaxError
#. What will be printed at the end this code block::
x = 20
if x > 10:
print x * 100
else:
print x
Answer: 2000
#. Convert the if else ladder below into a ternary conditional
statement::
x = 20
if x > 10:
print x * 100
else:
print x
Answer: print x * 100 if x > 10 else x
Larger Questions
----------------
.. A minimum of 2 questions here (along with answers)
1. Question 1
2. Question 2