conditionals/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Wed, 10 Nov 2010 12:32:16 +0530
changeset 437 0840aa06d2e6
parent 315 7944a4504769
child 438 4523b2048663
permissions -rw-r--r--
Parially cleaned up conditionals 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. 

2.