using python modules/questions.rst
author anoop
Sat, 09 Oct 2010 03:56:06 +0530
changeset 261 c7f0069d698a
permissions -rw-r--r--
added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.

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

.. A mininum of 8 questions here (along with answers)

1. What will be output of the following code snippet,
   ::

	from math import sqrt
        
	def sqrt(i):
       	    return i
	       
        print sqrt(49)

   a. 7.0
   #. 7
   #. 49
   #. 49.0
   #. Error

Answer: 49

2. What will be the output of the following code snippet,
   ::

        import math
        
        def sqrt(i):
            x = math.sqrt(i)
	    if int(x) == x:
	        return int(x)
	    else:
	        return x

        print math.sqrt(50), sqrt(50), math.sqrt(49), sqrt(49)

   a. 7.0710678118654755 7 7 7
   #. 7.0710678118654755 7 7.0 7
   #. 7 7 7 7
   #. 7.0710678118654755 7.0710678118654755 7.0 7

Answer: 7.0710678118654755, 7.0710678118654755, 7.0, 7

3. ``from math import *`` and ``import math`` does the same,

   a. True
   #. False

Answer: False

4. Which among these libraries is part of python standard library,

   a. Mayavi
   #. scipy
   #. matplotlib
   #. urllib2

Answer: urllib2

5. ``pylab.plot(x,sin(x))`` can be used in a script with ``from pylab
   import *``

   a. True
   #. False

Answer: False

6. Which among this is correct,

   a. from scipy import plot
   #. from numpy import plot
   #. from matplotlib import plot
   #. from pylab import plot
   #. None of the above

Answer: from pylab import plot

7. Functions ``xlim()`` and ``ylim()`` can be imported to the current
   name-space as,

   a. from pylab import xlim, ylim
   #. import pylab
   #. from scipy import xlim, ylim
   #. import scipy

Answer: from pylab import xlim, ylim

8. ``scipy.linspace(-5*scipy.pi, 5*scipy.pi, 500)``

   a. creates an array of 500 equally spaced elements from -5*scipy.pi
      to 5*scipy.pi(excluded)
   #. creates an array of 500 equally spaced elements from
      -5*scipy.pi(excluded) to 5*scipy.pi(included)
   #. creates an array of 500 equally spaced elements from -5*scipy.pi
      to 5*scipy.pi, both end points included
   #. created an array of 500 equally spaced elements from -5*scipy.pi
      to 5*scipy.pi, both end points excluded.
   #. None of the above

Answer: creates an array of 500 equally spaced elements from
	-5*scipy.pi to 5*scipy.pi, both end points included


Larger Questions
----------------

.. A minimum of 2 questions here (along with answers)

1. Write a python script to plot a red colour tan plot between -pi to
   pi, with x limits from -pi to pi. Label the figure appropriately
   and with a legend 'tan(x)' and title 'tangent plot'. Label the axes
   x as 'x' and y as 'tan(x)'. Make sure the script can be executed as
   a python script.

2. Write a python script to plot a parabola of the form y^2=4ax with a
   = 0.5(a is the directrix), plot the line in green color add the
   legend as 'y^2=4ax' and title as 'parabola'. For x from -20 to 20
   with 100 equidistant points. Make sure the script can be executed
   as a python script. [`Hint`: Use parametric equations]