additional_ipython/questions.rst
author Nishanth <nishanth@fossee.in>
Tue, 12 Oct 2010 11:26:09 +0530
changeset 334 4b1e81da1c80
parent 234 2b88724a7ee0
child 414 f76622c8cbd9
permissions -rw-r--r--
Finished using_sage_to_teach

Objective Questions
-------------------

 1. How do you retrieve the recent 5 commands

    a. ``%hist``
    #. ``%hist -5``
    #. ``%hist 5``
    #. ``%hist 5-10``

    Answer: ``%hist 5``
    
 2. If there were 20 commands typed and ``%hist`` is used. How many commands 
    will be displayed.

    a. 10
    #. 20
    #. 21
    #. 19

    Answer: 21

 3. is ``%hist`` considered as a command

    a. True
    #. False

    Answer: True

 4. how do you retreive the commands from 20 to 50 (inclusive of 20 and 50)

    a. ``%hist 20 50``
    #. ``%hist 19 50``
    #. ``%hist 19 51``
    #. ``%hist 21 50``

    Answer: ``%hist 20 50``

 5. What does the ``%hist 2 5 7`` command do

    a. lists the second, fifth and seventh commands
    #. lists the commands from 2 to 5 and the seventh command
    #. raises an error
    #. lists the commands 2 to 7

    Answer: raises an error

 6. How many commands are displayed when lot of coomands were typed and 
    ``%hist`` is used.

    a. 20
    #. 10
    #. 50
    #. 40

    Answer: 40

 7. How do you save the lines 2 3 4 5 7 9 10 11

    a. ``%save filepath 2-5 7 9-11``
    #. ``%save filepath 2-11``
    #. ``%save filepath``
    #. ``%save 2-5 7 9 10 11``

    Answer: ``%save filepath 2-5 7 9-11``

 8. You are working in /home/user. Where is the file saved when you do
    ``%save hello.py 1-3`` 

    a. /home/user/hello.py
    #. /hello.py
    #. /home/hello.py
    #. /home/user/ipython/hello.py

    Answer: /home/user/hello.py

 9. Which lines are saved by the command ``%save filepath 2-5 7 1`` and in
    which order

    a. 2 3 4 5 7 1
    #. 1 2 3 4 5 6 7
    #. 2 5 7 1
    #. 1 2 5 7

 10. What happens when ``%save filepath line_numbers`` is used and a file
     already exists in that path.

    a. It is overwritten
    #. The commands are added to the file
    #. It raises an error
    #. A prompt to confirm overwriting is displayed 

    Answer: A prompt to confirm overwriting is displayed 

 11. Read through the documentation of ``%hist`` and find its alternative name

    Answer: ``%history``

 12. Are ``%run /home/user/saved.py`` and ``%run /home/user/saved`` the same

   a. Yes
   #. No

   Answer: Yes

 13. The file hello.py contains only one command ``x = x + 1``. What happens
     when you do ``%run hello.py``

    Answer: Raises a nameerror

  14. The file hello.py contains only one command ``x = x + 1``. If value of x
      is 5 and what does ``%run -i hello.py`` do.

    a. raises an error
    #. increments value of x by 1
    #. Does nothing
    
    Answer: increments the value of x by 1