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