conditionals/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Tue, 09 Nov 2010 10:56:50 +0530
changeset 411 e227c45b0c3f
parent 315 7944a4504769
child 437 0840aa06d2e6
permissions -rw-r--r--
Merged heads.

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