question_bank.xml
author nishanth
Fri, 02 Jul 2010 14:12:25 +0530
changeset 87 e81b105b1128
parent 59 0b57494e8b4e
child 89 f8e25dea5222
permissions -rw-r--r--
found easier way to get things done. so removed all the junk code.

<questionbank>

<question>
<topic>Plotting</topic>
<description>
Describe the plot produced by the following code
</description>
<time_limit>
30
</time_limit>
<code>
In []: x = linspace(0, 2*pi, 50)
In []: plot(x, cos(x), 'go')
</code>
<expected_answer>
Correct this question manually
</expected_answer>
</question>

<question>
<topic>Plotting</topic>
<description>
What ipython magic command do you use to obtain the lines of code you have already typed in the interpreter? What command do you use to save them?
</description>
<time_limit>
30
</time_limit>
<expected_answer>
\%hist \%save
</expected_answer>
</question>

<question>
<topic>Plotting</topic>
<description>
How do you set the x and y labels of a plot to "x" and "sin(x)" ?
</description>
<time_limit>
60
</time_limit>
<expected_answer>
xlabel \( \" x \" \) ylabel \( \"sin\(x\)\" \)
xlabel \( \" x \" \) ylabel \( \'sin\(x\)\' \)
xlabel \( \' x \' \) ylabel \( \"sin\(x\)\" \)
xlabel \( \' x \' \) ylabel \( \'sin\(x\)\' \)
</expected_answer>
</question>

<question>
<topic>Plotting</topic>
<description>
How will you set the x and y axis limits so that the region of interest is in the rectangle (0, -1.5) and (2 pi, 1.5)?
</description>
<time_limit>
90
</time_limit>
<expected_answer>
xlim \( 0 , 2 \* pi \) [;,\n+] ylim \( -1\.5 , 1\.5 \)
</expected_answer>
</question>

<question>
<topic>Lists and Files</topic>
<description>
How do you combine two lists a and b to produce one list?
</description>
<time_limit>
30
</time_limit>
<expected_answer>
a \+ b
</expected_answer>
</question>

<question>
<topic>Lists and Files</topic>
<description>
If a = [1, 2, 5, 9] how do you add 10 to the end of this list ?
</description>
<time_limit>
30
</time_limit>
<expected_answer>
a\.append \( 10 \)
a = a \+ \[ 10 \]
a \+= \[ 10 \]
</expected_answer>
</question>

<question>
<topic>Lists and Files</topic>
<description>
Write the code to read a file "data.txt" and print each line of it?
</description>
<time_limit>
60
</time_limit>
<expected_answer>
correct this manually
</expected_answer>
</question>

<question>
<topic>For Loops</topic>
<description>
The following code snippet has an error/bug.
What is the error?
</description>
<code>
In []: l = [0.1, 0.2, 0.3, 0.4]
In []: t = [0.69, 0.90, 1.19, 1.30]
In []: tsq = []
In []: for time in t:
 ....:     tsq.append(time*time)
 ....:     plot(l, tsq)
</code>
<time_limit>
60
</time_limit>
<expected_answer>
plot
</expected_answer>
</question>

<question>
<topic>Strings</topic>
<description>
"Rossum, Guido, 42, 56, 34, 54" is a sample line from a Comma Separated Values (CSV) file
What code would you use to separate the line into fields?
</description>
<time_limit>
30
</time_limit>
<expected_answer>
\.split \( " , " \)
\.split \( ' , ' \)
</expected_answer>
</question>

<question>
<topic>Lists and Files</topic>
<description>
If a = [1, 2, 5, 9] how do you find the length of this list?
</description>
<time_limit>
30
</time_limit>
<expected_answer>
len \( a \)
</expected_answer>
</question>

<question>
<topic>Dictionaries and Piecharts</topic>
<description>
What is the output of the following code snippet
</description>
<code>
In [1]: d = {'a': 1,
             'b': 2
            }
In [2]: print d['c']
</code>
<time_limit>
30
</time_limit>
<expected_answer>
error
Error
ERROR
</expected_answer>
</question>

<question>
<topic>Dictionaries and Piecharts</topic>
<description>
Given the below dictionary, what command will you give to plot a pie-chart?
</description>
<code>
In []: sc = {'A': 10, 'B': 20, 'C': 70}
</code>
<time_limit>
60
</time_limit>
<expected_answer>
pie \( sc\.values \( \) \)
pie \( sc\.values \( \) , labels = sc\.keys \( \) \)
</expected_answer>
</question>

<question>
<topic>Statistics</topic>
<description>
Given the below marks, how will you calculate the mean?
</description>
<code>
In []: marks = [10, 20, 30, 50, 55, 75, 83] 
</code>
<time_limit>
30
</time_limit>
<expected_answer>
mean \( marks \)
sum \( marks \) \/ len \( marks \)
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>
How will you convert the list marks to an array?
</description>
<code>
In []: marks = [10, 20, 30, 50, 55, 75, 83]
</code>
<time_limit>
30
</time_limit>
<expected_answer>
array \( marks \)
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>
What is the value of a after executing this code.
</description>
<code>
In []: a = array([[1, 2],
                  [3, 4]])
In []: a[1,0] = 0
</code>
<time_limit>
60
</time_limit>
<expected_answer>
\[ \[ 1 , 2 \] , \[ 0 , 4 \] \]
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>
What will be printed?
</description>
<code>
In []: x = array(([1,2,3,4],
                  [2,3,4,5]))
In []: x[-2][-3] = 4
In []: print x
</code>
<time_limit>
90
</time_limit>
<expected_answer>
array \( \( \[ 4 , 2 , 3 , 4 \] , \[ 2 , 3 , 4 , 5 \] \) \)
array \( \[ \[ 4 , 2 , 3 , 4 \] , \[ 2 , 3 , 4 , 5 \] \] \)
\[ \[ 4 , 2 , 3 , 4 \] , \[ 2 , 3 , 4 , 5 \] \]
\( \[ 4 , 2 , 3 , 4 \] , \[ 2 , 3 , 4 , 5 \] \)
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>
If x = array([[1,2,3,4]]) How to change x to array([[1,2,0,4]]) ?
</description>
<time_limit>
60
</time_limit>
<expected_answer>
x\[ 0 \]\[ 2 \] = 0
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>

x = array([[1,2,3,4],
           [3,4,2,5]])
		 
How do you get the following slice of x ?

array([[2,3],
      [4,2]])
       
</description>
<time_limit>
60
</time_limit>
<expected_answer>
x\[ \: , 1 \: 3 \]
x\[ \: , 1 \: -1 \]
x\[ \: , -3 \: -1 \]
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>
What is the output of x[::3,::3]
</description>
<code>
In []: x = array([[9,18,27],
                  [30,60,90],
                  [14,7,1]])
</code>
<time_limit>
30
</time_limit>
<expected_answer>
9
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>
How do you get the transpose of this array?
</description>
<code>
In []: a = array([[1, 2],
                  [3, 4]])
</code>
<time_limit>
30
</time_limit>
<expected_answer>
a\.T
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>
What does this produce?
</description>
<code>
In []: a = array([[1, 2],
                  [3, 4]])
In []: b = array([[1, 1],
                  [2, 2]])
In []: a*b
</code>
<time_limit>
45
</time_limit>
<expected_answer>
array \( \[ \[ 1 , 2 \] , \[ 6 , 8 \] \] \)
\[ \[ 1 , 2 \] , \[ 6 , 8 \] \]
</expected_answer>
</question>

<question>
<topic>Arrays and Matrices</topic>
<description>
What command do you use to find the inverse of a matrix and its eigenvalues?
</description>
<time_limit>
30
</time_limit>
<expected_answer>
inv .* eigvals
</expected_answer>
</question>

<question>
<topic>Solving linear equations</topic>
<description>
Given a 4x4 matrix A and a 4-vector b , what command do you use to solve for the equation Ax = b ?
</description>
<time_limit>
45
</time_limit>
<expected_answer>
solve \( A , b \)
</expected_answer>
</question>

<question>
<topic>Finding roots</topic>
<description>
How do you calculate the roots of the polynomial, y = 1 + 6*x + 8*x^2 + x^3 
</description>
<time_limit>
45
</time_limit>
<expected_answer>
roots \( \[ 1 , 8 , 6 , 1 \] \)
</expected_answer>
</question>

<question>
<topic>Solving linear equations</topic>
<description>
Two arrays a and b are numerically almost equal, what command do you use to check if this is true?
</description>
<time_limit>
30
</time_limit>
<expected_answer>
allclose \( a , b \)
allclose \( b , a \)
</expected_answer>
</question>

<question>
<topic>Basic Datatypes</topic>
<description>
What is the largest integer value that can be represented by Python?
</description>
<time_limit>
30
</time_limit>
<options>
No Limit
2**32
2**32 - 1
None of the above
</options>
<expected_answer>
No Limit
</expected_answer>
</question>

<question>
<topic>Basic Datatypes</topic>
<description>
What is the result of 17.0 / 2?
</description>
<time_limit>
15
</time_limit>
<expected_answer>
8.5
</expected_answer>
</question>

<question>
<topic>Basic Datatypes</topic>
<description>
Which of the following is not a type in Python?
</description>
<time_limit>
30
</time_limit>
<options>
int
float
char
string
</options>
<expected_answer>
char
</expected_answer>
</question>


<question>
<topic>Basic Datatypes</topic>
<description>
How do you create a complex number with real part 2 and imaginary part 0.5 ?
</description>
<time_limit>
30
</time_limit>
<expected_answer>
2 \+ 0\.5j
complex \( 2 , 0\.5 \)
</expected_answer>
</question>

<question>
<topic>Input and Output</topic>
<description>
What is the difference between print x and print x,
</description>
<time_limit>
30
</time_limit>
<expected_answer>
correct manually
</expected_answer>
</question>

<question>
<topic>Input and Output</topic>
<description>
What does 't' * 40 produce?
</description>
<time_limit>
30
</time_limit>
<options>
40
tttttttttttttttttttttttttttttttttttttttt
t40
Error
</options>
<expected_answer>
tttttttttttttttttttttttttttttttttttttttt
</expected_answer>
</question>

<question>
<topic>Basic Datatypes</topic>
<description>
What is the output?
</description>
<code>
In []: ', '.join(['a', 'b', 'c'])
</code>
<time_limit>
30
</time_limit>
<expected_answer>
"a, b, c"
'a, b, c'
</expected_answer>
</question>

<question>
<topic>Basic Datatypes</topic>
<description>
What is the output?
</description>
<code>
In []: 47 % 3 
</code>
<time_limit>
45
</time_limit>
<expected_answer>
2
</expected_answer>
</question>

<question>
<topic>Lists and Tuples</topic>
<description>
How do you find the presence of an element x in the list a
</description>
<time_limit>
30
</time_limit>
<expected_answer>
x in a
</expected_answer>
</question>

<question>
<topic>Sets</topic>
<description>
What is the output
</description>
<code>
In []: set([1, 2, 8, 2, 13, 8, 9])
</code>
<time_limit>
45
</time_limit>
<expected_answer>
set \( \[ 1 , 2 , 8 , 13 , 9 \] \)
\[ 1 , 2 , 8 , 13 , 9 \]
</expected_answer>
</question>

<question>
<topic>Dictionaries</topic>
<description>
What is the output
</description>
<code>
In []: a = {'a': 1, 'b': 2} 
In []: a['a'] = 10
In []: print a
</code>
<time_limit>
60
</time_limit>
<expected_answer>
\{ \'a\' \: 10 , \'b\' \: 2 \}
\{ \'a\' \: 10 , \"b\" \: 2 \}
\{ \"a\" \: 10 , \"b\" \: 2 \}
\{ \"a\" \: 10 , \'b\' \: 2 \}
</expected_answer>
</question>

<question>
<topic>Lists and Tuples</topic>
<description>
What is the value of a after executing this code.
</description>
<code>
In []: a = [1, 2, 3] 
In []: a.extend([5, 6])
</code>
<time_limit>
45
</time_limit>
<expected_answer>
\[ 1 , 2 , 3 , 5 , 6 \]
</expected_answer>
</question>

<question>
<topic>Lists and Tuples</topic>
<description>
What is the output?
</description>
<code>
In []: a = (1, 2, 3)
In []: a[1] = 10
</code>
<time_limit>
30
</time_limit>
<expected_answer>
error
Error
ERROR
</expected_answer>
</question>

<question>
<topic>Functions</topic>
<description>
What is the value of func(1), if
</description>
<code>
def func(x, y=10):
    print x+1, y+10
</code>
<time_limit>
60
</time_limit>
<expected_answer>
2 20
</expected_answer>
</question>

<question>
<topic>Functions</topic>
<description>
How many items can a function return ?
</description>
<time_limit>
30
</time_limit>
<options>
One
Multiple
Two
None
</options>
<expected_answer>
Multiple
</expected_answer>
</question>

</questionbank>