conditionals/questions.rst
changeset 315 7944a4504769
child 437 0840aa06d2e6
equal deleted inserted replaced
314:11869b16d86b 315:7944a4504769
       
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4 .. A mininum of 8 questions here (along with answers)
       
     5 
       
     6 1. Given a variable ``time``, print ``Good Morning`` if it is less
       
     7    than 12, otherwise ``Hello``. 
       
     8 
       
     9    Answer::
       
    10      
       
    11      if time < 12:
       
    12          print "Good Morning"
       
    13 
       
    14      else:
       
    15          print "Hello"
       
    16 
       
    17 #. Every ``if`` block must be followed by an ``else`` block. T or F?
       
    18 
       
    19    Answer: F
       
    20 
       
    21 #. Every ``if/elif/else`` ladder MUST end with an ``else`` block. T/F?
       
    22 
       
    23    Answer: F
       
    24 
       
    25 #. An if/elif/else ladder can have any number of elif blocks. T or F?
       
    26 
       
    27    Answer: T
       
    28 
       
    29 #. What will be printed at the end this code block::
       
    30    
       
    31      x = 20
       
    32 
       
    33      if x > 10:
       
    34      print x * 100
       
    35    
       
    36    Answer: IndentationError - Expected and indented block.. 
       
    37 
       
    38 #. What will be printed at the end this code block::
       
    39    
       
    40      x = 20
       
    41 
       
    42      if x > 10:
       
    43          print x * 100
       
    44          else:
       
    45              print x
       
    46 
       
    47    Answer: SyntaxError
       
    48 
       
    49 #. What will be printed at the end this code block::
       
    50    
       
    51      x = 20
       
    52 
       
    53      if x > 10:
       
    54          print x * 100
       
    55      else:
       
    56          print x
       
    57 
       
    58    Answer: 2000
       
    59 
       
    60 #. Convert the if else ladder below into a ternary conditional
       
    61    statement::
       
    62    
       
    63      x = 20
       
    64 
       
    65      if x > 10:
       
    66          print x * 100
       
    67      else:
       
    68          print x
       
    69 
       
    70    Answer: print x * 100 if x > 10 else x
       
    71 
       
    72 
       
    73 Larger Questions
       
    74 ----------------
       
    75 
       
    76 .. A minimum of 2 questions here (along with answers)
       
    77 
       
    78 1. Question 1
       
    79 2. Question 2