additional_ipython/questions.rst
changeset 234 2b88724a7ee0
child 414 f76622c8cbd9
equal deleted inserted replaced
233:ab748264f726 234:2b88724a7ee0
       
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4  1. How do you retrieve the recent 5 commands
       
     5 
       
     6     a. ``%hist``
       
     7     #. ``%hist -5``
       
     8     #. ``%hist 5``
       
     9     #. ``%hist 5-10``
       
    10 
       
    11     Answer: ``%hist 5``
       
    12     
       
    13  2. If there were 20 commands typed and ``%hist`` is used. How many commands 
       
    14     will be displayed.
       
    15 
       
    16     a. 10
       
    17     #. 20
       
    18     #. 21
       
    19     #. 19
       
    20 
       
    21     Answer: 21
       
    22 
       
    23  3. is ``%hist`` considered as a command
       
    24 
       
    25     a. True
       
    26     #. False
       
    27 
       
    28     Answer: True
       
    29 
       
    30  4. how do you retreive the commands from 20 to 50 (inclusive of 20 and 50)
       
    31 
       
    32     a. ``%hist 20 50``
       
    33     #. ``%hist 19 50``
       
    34     #. ``%hist 19 51``
       
    35     #. ``%hist 21 50``
       
    36 
       
    37     Answer: ``%hist 20 50``
       
    38 
       
    39  5. What does the ``%hist 2 5 7`` command do
       
    40 
       
    41     a. lists the second, fifth and seventh commands
       
    42     #. lists the commands from 2 to 5 and the seventh command
       
    43     #. raises an error
       
    44     #. lists the commands 2 to 7
       
    45 
       
    46     Answer: raises an error
       
    47 
       
    48  6. How many commands are displayed when lot of coomands were typed and 
       
    49     ``%hist`` is used.
       
    50 
       
    51     a. 20
       
    52     #. 10
       
    53     #. 50
       
    54     #. 40
       
    55 
       
    56     Answer: 40
       
    57 
       
    58  7. How do you save the lines 2 3 4 5 7 9 10 11
       
    59 
       
    60     a. ``%save filepath 2-5 7 9-11``
       
    61     #. ``%save filepath 2-11``
       
    62     #. ``%save filepath``
       
    63     #. ``%save 2-5 7 9 10 11``
       
    64 
       
    65     Answer: ``%save filepath 2-5 7 9-11``
       
    66 
       
    67  8. You are working in /home/user. Where is the file saved when you do
       
    68     ``%save hello.py 1-3`` 
       
    69 
       
    70     a. /home/user/hello.py
       
    71     #. /hello.py
       
    72     #. /home/hello.py
       
    73     #. /home/user/ipython/hello.py
       
    74 
       
    75     Answer: /home/user/hello.py
       
    76 
       
    77  9. Which lines are saved by the command ``%save filepath 2-5 7 1`` and in
       
    78     which order
       
    79 
       
    80     a. 2 3 4 5 7 1
       
    81     #. 1 2 3 4 5 6 7
       
    82     #. 2 5 7 1
       
    83     #. 1 2 5 7
       
    84 
       
    85  10. What happens when ``%save filepath line_numbers`` is used and a file
       
    86      already exists in that path.
       
    87 
       
    88     a. It is overwritten
       
    89     #. The commands are added to the file
       
    90     #. It raises an error
       
    91     #. A prompt to confirm overwriting is displayed 
       
    92 
       
    93     Answer: A prompt to confirm overwriting is displayed 
       
    94 
       
    95  11. Read through the documentation of ``%hist`` and find its alternative name
       
    96 
       
    97     Answer: ``%history``
       
    98 
       
    99  12. Are ``%run /home/user/saved.py`` and ``%run /home/user/saved`` the same
       
   100 
       
   101    a. Yes
       
   102    #. No
       
   103 
       
   104    Answer: Yes
       
   105 
       
   106  13. The file hello.py contains only one command ``x = x + 1``. What happens
       
   107      when you do ``%run hello.py``
       
   108 
       
   109     Answer: Raises a nameerror
       
   110 
       
   111   14. The file hello.py contains only one command ``x = x + 1``. If value of x
       
   112       is 5 and what does ``%run -i hello.py`` do.
       
   113 
       
   114     a. raises an error
       
   115     #. increments value of x by 1
       
   116     #. Does nothing
       
   117     
       
   118     Answer: increments the value of x by 1