additional_ipython/questions.rst
author bhanu
Thu, 11 Nov 2010 03:00:24 +0530
changeset 480 42f7aa36f1bc
parent 414 f76622c8cbd9
permissions -rw-r--r--
language check done for `getting started with functions`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
234
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     1
Objective Questions
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     2
-------------------
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     3
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     4
 1. How do you retrieve the recent 5 commands
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     5
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     6
    a. ``%hist``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     7
    #. ``%hist -5``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     8
    #. ``%hist 5``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     9
    #. ``%hist 5-10``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    10
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    11
    Answer: ``%hist 5``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    12
    
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    13
 2. If there were 20 commands typed and ``%hist`` is used. How many commands 
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    14
    will be displayed.
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    15
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    16
    a. 10
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    17
    #. 20
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    18
    #. 21
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    19
    #. 19
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    20
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    21
    Answer: 21
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    22
414
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
    23
.. #[Amit: I really don't get the question below]
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
    24
 
234
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    25
 3. is ``%hist`` considered as a command
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    26
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    27
    a. True
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    28
    #. False
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    29
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    30
    Answer: True
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    31
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    32
 4. how do you retreive the commands from 20 to 50 (inclusive of 20 and 50)
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    33
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    34
    a. ``%hist 20 50``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    35
    #. ``%hist 19 50``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    36
    #. ``%hist 19 51``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    37
    #. ``%hist 21 50``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    38
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    39
    Answer: ``%hist 20 50``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    40
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    41
 5. What does the ``%hist 2 5 7`` command do
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    42
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    43
    a. lists the second, fifth and seventh commands
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    44
    #. lists the commands from 2 to 5 and the seventh command
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    45
    #. raises an error
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    46
    #. lists the commands 2 to 7
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    47
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    48
    Answer: raises an error
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    49
414
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
    50
 6. How many commands are displayed when lot of commands were typed and 
234
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    51
    ``%hist`` is used.
414
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
    52
.. #[Amit: Ok something wrong with the question. 
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
    53
.. Recommend : What is the default maximum number of commands %hist can show ]
234
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    54
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    55
    a. 20
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    56
    #. 10
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    57
    #. 50
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    58
    #. 40
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    59
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    60
    Answer: 40
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    61
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    62
 7. How do you save the lines 2 3 4 5 7 9 10 11
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    63
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    64
    a. ``%save filepath 2-5 7 9-11``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    65
    #. ``%save filepath 2-11``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    66
    #. ``%save filepath``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    67
    #. ``%save 2-5 7 9 10 11``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    68
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    69
    Answer: ``%save filepath 2-5 7 9-11``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    70
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    71
 8. You are working in /home/user. Where is the file saved when you do
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    72
    ``%save hello.py 1-3`` 
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    73
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    74
    a. /home/user/hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    75
    #. /hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    76
    #. /home/hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    77
    #. /home/user/ipython/hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    78
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    79
    Answer: /home/user/hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    80
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    81
 9. Which lines are saved by the command ``%save filepath 2-5 7 1`` and in
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    82
    which order
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    83
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    84
    a. 2 3 4 5 7 1
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    85
    #. 1 2 3 4 5 6 7
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    86
    #. 2 5 7 1
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    87
    #. 1 2 5 7
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    88
414
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
    89
    Answer: a
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
    90
 
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
    91
10. What happens when ``%save filepath line_numbers`` is used and a file
234
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    92
     already exists in that path.
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    93
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    94
    a. It is overwritten
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    95
    #. The commands are added to the file
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    96
    #. It raises an error
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    97
    #. A prompt to confirm overwriting is displayed 
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    98
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    99
    Answer: A prompt to confirm overwriting is displayed 
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   100
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   101
 11. Read through the documentation of ``%hist`` and find its alternative name
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   102
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   103
    Answer: ``%history``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   104
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   105
 12. Are ``%run /home/user/saved.py`` and ``%run /home/user/saved`` the same
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   106
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   107
   a. Yes
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   108
   #. No
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   109
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   110
   Answer: Yes
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   111
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   112
 13. The file hello.py contains only one command ``x = x + 1``. What happens
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   113
     when you do ``%run hello.py``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   114
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   115
    Answer: Raises a nameerror
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   116
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   117
  14. The file hello.py contains only one command ``x = x + 1``. If value of x
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   118
      is 5 and what does ``%run -i hello.py`` do.
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   119
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   120
    a. raises an error
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   121
    #. increments value of x by 1
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   122
    #. Does nothing
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   123
    
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   124
    Answer: increments the value of x by 1
414
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   125
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   126
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   127
Long Answer questions :
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   128
-----------------------
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   129
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   130
1. Question 1
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   131
2. Question 2
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   132
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   133
.. #[Amit: I think long answer questions for this script are
f76622c8cbd9 Review of addition ipython
Amit Sethi
parents: 234
diff changeset
   134
.. not possible. Please add if someone comes up with any]