additional_ipython/questions.rst
changeset 522 d33698326409
parent 521 88a01948450d
child 523 54bdda4aefa5
equal deleted inserted replaced
521:88a01948450d 522:d33698326409
     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 .. #[Amit: I really don't get the question below]
       
    24  
       
    25  3. is ``%hist`` considered as a command
       
    26 
       
    27     a. True
       
    28     #. False
       
    29 
       
    30     Answer: True
       
    31 
       
    32  4. how do you retreive the commands from 20 to 50 (inclusive of 20 and 50)
       
    33 
       
    34     a. ``%hist 20 50``
       
    35     #. ``%hist 19 50``
       
    36     #. ``%hist 19 51``
       
    37     #. ``%hist 21 50``
       
    38 
       
    39     Answer: ``%hist 20 50``
       
    40 
       
    41  5. What does the ``%hist 2 5 7`` command do
       
    42 
       
    43     a. lists the second, fifth and seventh commands
       
    44     #. lists the commands from 2 to 5 and the seventh command
       
    45     #. raises an error
       
    46     #. lists the commands 2 to 7
       
    47 
       
    48     Answer: raises an error
       
    49 
       
    50  6. How many commands are displayed when lot of commands were typed and 
       
    51     ``%hist`` is used.
       
    52 .. #[Amit: Ok something wrong with the question. 
       
    53 .. Recommend : What is the default maximum number of commands %hist can show ]
       
    54 
       
    55     a. 20
       
    56     #. 10
       
    57     #. 50
       
    58     #. 40
       
    59 
       
    60     Answer: 40
       
    61 
       
    62  7. How do you save the lines 2 3 4 5 7 9 10 11
       
    63 
       
    64     a. ``%save filepath 2-5 7 9-11``
       
    65     #. ``%save filepath 2-11``
       
    66     #. ``%save filepath``
       
    67     #. ``%save 2-5 7 9 10 11``
       
    68 
       
    69     Answer: ``%save filepath 2-5 7 9-11``
       
    70 
       
    71  8. You are working in /home/user. Where is the file saved when you do
       
    72     ``%save hello.py 1-3`` 
       
    73 
       
    74     a. /home/user/hello.py
       
    75     #. /hello.py
       
    76     #. /home/hello.py
       
    77     #. /home/user/ipython/hello.py
       
    78 
       
    79     Answer: /home/user/hello.py
       
    80 
       
    81  9. Which lines are saved by the command ``%save filepath 2-5 7 1`` and in
       
    82     which order
       
    83 
       
    84     a. 2 3 4 5 7 1
       
    85     #. 1 2 3 4 5 6 7
       
    86     #. 2 5 7 1
       
    87     #. 1 2 5 7
       
    88 
       
    89     Answer: a
       
    90  
       
    91 10. What happens when ``%save filepath line_numbers`` is used and a file
       
    92      already exists in that path.
       
    93 
       
    94     a. It is overwritten
       
    95     #. The commands are added to the file
       
    96     #. It raises an error
       
    97     #. A prompt to confirm overwriting is displayed 
       
    98 
       
    99     Answer: A prompt to confirm overwriting is displayed 
       
   100 
       
   101  11. Read through the documentation of ``%hist`` and find its alternative name
       
   102 
       
   103     Answer: ``%history``
       
   104 
       
   105  12. Are ``%run /home/user/saved.py`` and ``%run /home/user/saved`` the same
       
   106 
       
   107    a. Yes
       
   108    #. No
       
   109 
       
   110    Answer: Yes
       
   111 
       
   112  13. The file hello.py contains only one command ``x = x + 1``. What happens
       
   113      when you do ``%run hello.py``
       
   114 
       
   115     Answer: Raises a nameerror
       
   116 
       
   117   14. The file hello.py contains only one command ``x = x + 1``. If value of x
       
   118       is 5 and what does ``%run -i hello.py`` do.
       
   119 
       
   120     a. raises an error
       
   121     #. increments value of x by 1
       
   122     #. Does nothing
       
   123     
       
   124     Answer: increments the value of x by 1
       
   125 
       
   126 
       
   127 Long Answer questions :
       
   128 -----------------------
       
   129 
       
   130 1. Question 1
       
   131 2. Question 2
       
   132 
       
   133 .. #[Amit: I think long answer questions for this script are
       
   134 .. not possible. Please add if someone comes up with any]