additional_ipython/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Wed, 13 Oct 2010 12:52:11 +0530
changeset 318 a45256cc5404
parent 234 2b88724a7ee0
child 414 f76622c8cbd9
permissions -rw-r--r--
Reviewed getting started with arrays, script.
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
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    23
 3. is ``%hist`` considered as a command
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    24
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    25
    a. True
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    26
    #. False
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    27
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    28
    Answer: True
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
 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
    31
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    32
    a. ``%hist 20 50``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    33
    #. ``%hist 19 50``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    34
    #. ``%hist 19 51``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    35
    #. ``%hist 21 50``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    36
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    37
    Answer: ``%hist 20 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
 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
    40
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    41
    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
    42
    #. 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
    43
    #. raises an error
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    44
    #. lists the commands 2 to 7
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    45
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    46
    Answer: raises an error
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
 6. How many commands are displayed when lot of coomands were typed and 
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    49
    ``%hist`` is used.
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    50
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    51
    a. 20
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    52
    #. 10
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    53
    #. 50
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    54
    #. 40
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    55
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    56
    Answer: 40
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    57
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    58
 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
    59
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    60
    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
    61
    #. ``%save filepath 2-11``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    62
    #. ``%save filepath``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    63
    #. ``%save 2-5 7 9 10 11``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    64
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    65
    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
    66
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    67
 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
    68
    ``%save hello.py 1-3`` 
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    69
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    70
    a. /home/user/hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    71
    #. /hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    72
    #. /home/hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    73
    #. /home/user/ipython/hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    74
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    75
    Answer: /home/user/hello.py
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    76
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    77
 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
    78
    which order
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    79
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    80
    a. 2 3 4 5 7 1
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    81
    #. 1 2 3 4 5 6 7
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    82
    #. 2 5 7 1
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    83
    #. 1 2 5 7
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    84
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    85
 10. What happens when ``%save filepath line_numbers`` is used and a file
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    86
     already exists in that path.
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    87
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    88
    a. It is overwritten
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    89
    #. The commands are added to the file
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    90
    #. It raises an error
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    91
    #. A prompt to confirm overwriting is displayed 
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    92
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    93
    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
    94
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    95
 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
    96
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    97
    Answer: ``%history``
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
 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
   100
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   101
   a. Yes
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   102
   #. No
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   103
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   104
   Answer: Yes
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   105
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   106
 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
   107
     when you do ``%run hello.py``
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   108
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   109
    Answer: Raises a nameerror
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   110
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   111
  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
   112
      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
   113
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   114
    a. raises an error
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   115
    #. increments value of x by 1
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   116
    #. Does nothing
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   117
    
2b88724a7ee0 Converted the additional_ipython script into new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   118
    Answer: increments the value of x by 1