input_output/questions.rst
changeset 236 33828497b5da
equal deleted inserted replaced
235:80e4016d747a 236:33828497b5da
       
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4  1. ``a = 2.5``. What is the output of ``print "a is %d"%(a)``
       
     5 
       
     6    a. a is 2.5
       
     7    #. a is 2.0
       
     8    #. 2.0
       
     9    #. a is 2
       
    10 
       
    11    Answer: a is 2
       
    12 
       
    13  2. What does ``print "This is",     "a line ", "with  spaces"`` print?
       
    14 
       
    15    a. This is a line with spaces
       
    16    #. This is a line with  spaces
       
    17    #. This is     a line   with   spaces
       
    18    #. This is a line  with  spaces
       
    19 
       
    20    Answer: This is a line  with  spaces
       
    21 
       
    22  3. What does ``print "%2.5f"%(1.2)`` print?
       
    23 
       
    24    a. 1.2
       
    25    #. 1.20
       
    26    #. 1.20000
       
    27    #. 00001.2
       
    28 
       
    29    Answer: 1.20000
       
    30 
       
    31  4. What is the output of the following code::
       
    32 
       
    33      for i in range(1,10,2):
       
    34          print i,
       
    35 
       
    36     Answer::
       
    37 
       
    38       1 3 5 7 9
       
    39 
       
    40  5. ``a = 2`` and ``b = 4.5``. What does ``print "a is %d and b is %2.1f"%(b, a)``
       
    41     print?
       
    42 
       
    43    a. a is 2 and b is 4.5
       
    44    #. a is 4 and b is 2
       
    45    #. a is 4 and b is 2.0
       
    46    #. a is 4.5 and b is 2
       
    47 
       
    48    Answer: a is 4 and b is 2.0
       
    49 
       
    50  6. What is the prompt displayed by ``raw_input("Say something\nType here:")``
       
    51 
       
    52    Answer::
       
    53 
       
    54      Say something 
       
    55      Type here:
       
    56 
       
    57  6. What is the prompt displayed by ``raw_input("value of a is %d\nInput b
       
    58     value:"a)`` and ``a = 2.5``
       
    59 
       
    60    Answer::
       
    61 
       
    62      value of a is 2
       
    63      Input ba value:
       
    64 
       
    65  7. ``a = raw_input()`` and user enters ``2.5``. What is the type of a?
       
    66 
       
    67    a. str
       
    68    #. int
       
    69    #. float
       
    70    #. char
       
    71 
       
    72    Answer: str
       
    73 
       
    74  8. ``a = int(raw_input())`` and user enters ``4.5``. What happens?
       
    75 
       
    76    a. a = 4.5
       
    77    #. a = 4
       
    78    #. a = 4.0
       
    79    #. Error
       
    80 
       
    81    Answer: Error
       
    82 
       
    83  9. ``a = raw_input()`` and user enters ``"this is a string"``. What does 
       
    84     ``print a`` produce?
       
    85 
       
    86    a. 'this is a string'
       
    87    b. 'this is a string"
       
    88    c. "this is a string"
       
    89    #. this is a string
       
    90 
       
    91    Answer: "this is a string"
       
    92 
       
    93 Larger Questions
       
    94 ================
       
    95 
       
    96  1. Answer to universe and everything. Keep taking input from user and print it
       
    97     back until the input is 42.
       
    98 
       
    99   Answer::
       
   100 
       
   101     ip = raw_input()
       
   102     while ip != "42":
       
   103         print ip
       
   104 
       
   105