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