question_bank.xml
changeset 89 f8e25dea5222
parent 59 0b57494e8b4e
equal deleted inserted replaced
88:281c4bcf848f 89:f8e25dea5222
     4 <topic>Plotting</topic>
     4 <topic>Plotting</topic>
     5 <description>
     5 <description>
     6 Describe the plot produced by the following code
     6 Describe the plot produced by the following code
     7 </description>
     7 </description>
     8 <time_limit>
     8 <time_limit>
     9 30
     9 90
    10 </time_limit>
    10 </time_limit>
    11 <code>
    11 <code>
    12 In []: x = linspace(0, 2*pi, 50)
    12 In []: x = linspace(0, 2*pi, 50)
    13 In []: plot(x, cos(x), 'go')
    13 In []: plot(x, cos(x), 'go')
    14 </code>
    14 </code>
    21 <topic>Plotting</topic>
    21 <topic>Plotting</topic>
    22 <description>
    22 <description>
    23 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?
    23 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?
    24 </description>
    24 </description>
    25 <time_limit>
    25 <time_limit>
    26 30
    26 60
    27 </time_limit>
    27 </time_limit>
    28 <expected_answer>
    28 <expected_answer>
    29 \%hist \%save
    29 \%hist \%save
    30 </expected_answer>
    30 </expected_answer>
    31 </question>
    31 </question>
    34 <topic>Plotting</topic>
    34 <topic>Plotting</topic>
    35 <description>
    35 <description>
    36 How do you set the x and y labels of a plot to "x" and "sin(x)" ?
    36 How do you set the x and y labels of a plot to "x" and "sin(x)" ?
    37 </description>
    37 </description>
    38 <time_limit>
    38 <time_limit>
    39 60
    39 75
    40 </time_limit>
    40 </time_limit>
    41 <expected_answer>
    41 <expected_answer>
    42 xlabel \( \" x \" \) ylabel \( \"sin\(x\)\" \)
    42 xlabel \( \" x \" \) ylabel \( \"sin\(x\)\" \)
    43 xlabel \( \" x \" \) ylabel \( \'sin\(x\)\' \)
    43 xlabel \( \" x \" \) ylabel \( \'sin\(x\)\' \)
    44 xlabel \( \' x \' \) ylabel \( \"sin\(x\)\" \)
    44 xlabel \( \' x \' \) ylabel \( \"sin\(x\)\" \)
    63 <topic>Lists and Files</topic>
    63 <topic>Lists and Files</topic>
    64 <description>
    64 <description>
    65 How do you combine two lists a and b to produce one list?
    65 How do you combine two lists a and b to produce one list?
    66 </description>
    66 </description>
    67 <time_limit>
    67 <time_limit>
    68 30
    68 45
    69 </time_limit>
    69 </time_limit>
    70 <expected_answer>
    70 <expected_answer>
    71 a \+ b
    71 a \+ b
    72 </expected_answer>
    72 </expected_answer>
    73 </question>
    73 </question>
    76 <topic>Lists and Files</topic>
    76 <topic>Lists and Files</topic>
    77 <description>
    77 <description>
    78 If a = [1, 2, 5, 9] how do you add 10 to the end of this list ?
    78 If a = [1, 2, 5, 9] how do you add 10 to the end of this list ?
    79 </description>
    79 </description>
    80 <time_limit>
    80 <time_limit>
    81 30
    81 60
    82 </time_limit>
    82 </time_limit>
    83 <expected_answer>
    83 <expected_answer>
    84 a\.append \( 10 \)
    84 a\.append \( 10 \)
    85 a = a \+ \[ 10 \]
    85 a = a \+ \[ 10 \]
    86 a \+= \[ 10 \]
    86 a \+= \[ 10 \]
    91 <topic>Lists and Files</topic>
    91 <topic>Lists and Files</topic>
    92 <description>
    92 <description>
    93 Write the code to read a file "data.txt" and print each line of it?
    93 Write the code to read a file "data.txt" and print each line of it?
    94 </description>
    94 </description>
    95 <time_limit>
    95 <time_limit>
    96 60
    96 90
    97 </time_limit>
    97 </time_limit>
    98 <expected_answer>
    98 <expected_answer>
    99 correct this manually
    99 correct this manually
   100 </expected_answer>
   100 </expected_answer>
   101 </question>
   101 </question>
   113 In []: for time in t:
   113 In []: for time in t:
   114  ....:     tsq.append(time*time)
   114  ....:     tsq.append(time*time)
   115  ....:     plot(l, tsq)
   115  ....:     plot(l, tsq)
   116 </code>
   116 </code>
   117 <time_limit>
   117 <time_limit>
   118 60
   118 75
   119 </time_limit>
   119 </time_limit>
   120 <expected_answer>
   120 <expected_answer>
   121 plot
   121 plot
   122 </expected_answer>
   122 </expected_answer>
   123 </question>
   123 </question>
   127 <description>
   127 <description>
   128 "Rossum, Guido, 42, 56, 34, 54" is a sample line from a Comma Separated Values (CSV) file
   128 "Rossum, Guido, 42, 56, 34, 54" is a sample line from a Comma Separated Values (CSV) file
   129 What code would you use to separate the line into fields?
   129 What code would you use to separate the line into fields?
   130 </description>
   130 </description>
   131 <time_limit>
   131 <time_limit>
   132 30
   132 45
   133 </time_limit>
   133 </time_limit>
   134 <expected_answer>
   134 <expected_answer>
   135 \.split \( " , " \)
   135 \.split \( " , " \)
   136 \.split \( ' , ' \)
   136 \.split \( ' , ' \)
   137 </expected_answer>
   137 </expected_answer>
   141 <topic>Lists and Files</topic>
   141 <topic>Lists and Files</topic>
   142 <description>
   142 <description>
   143 If a = [1, 2, 5, 9] how do you find the length of this list?
   143 If a = [1, 2, 5, 9] how do you find the length of this list?
   144 </description>
   144 </description>
   145 <time_limit>
   145 <time_limit>
   146 30
   146 45
   147 </time_limit>
   147 </time_limit>
   148 <expected_answer>
   148 <expected_answer>
   149 len \( a \)
   149 len \( a \)
   150 </expected_answer>
   150 </expected_answer>
   151 </question>
   151 </question>
   160              'b': 2
   160              'b': 2
   161             }
   161             }
   162 In [2]: print d['c']
   162 In [2]: print d['c']
   163 </code>
   163 </code>
   164 <time_limit>
   164 <time_limit>
   165 30
   165 60
   166 </time_limit>
   166 </time_limit>
   167 <expected_answer>
   167 <expected_answer>
   168 error
   168 error
   169 Error
   169 Error
   170 ERROR
   170 ERROR
   178 </description>
   178 </description>
   179 <code>
   179 <code>
   180 In []: sc = {'A': 10, 'B': 20, 'C': 70}
   180 In []: sc = {'A': 10, 'B': 20, 'C': 70}
   181 </code>
   181 </code>
   182 <time_limit>
   182 <time_limit>
   183 60
   183 75
   184 </time_limit>
   184 </time_limit>
   185 <expected_answer>
   185 <expected_answer>
   186 pie \( sc\.values \( \) \)
   186 pie \( sc\.values \( \) \)
   187 pie \( sc\.values \( \) , labels = sc\.keys \( \) \)
   187 pie \( sc\.values \( \) , labels = sc\.keys \( \) \)
   188 </expected_answer>
   188 </expected_answer>
   195 </description>
   195 </description>
   196 <code>
   196 <code>
   197 In []: marks = [10, 20, 30, 50, 55, 75, 83] 
   197 In []: marks = [10, 20, 30, 50, 55, 75, 83] 
   198 </code>
   198 </code>
   199 <time_limit>
   199 <time_limit>
   200 30
   200 60
   201 </time_limit>
   201 </time_limit>
   202 <expected_answer>
   202 <expected_answer>
   203 mean \( marks \)
   203 mean \( marks \)
   204 sum \( marks \) \/ len \( marks \)
   204 sum \( marks \) \/ len \( marks \)
   205 </expected_answer>
   205 </expected_answer>
   212 </description>
   212 </description>
   213 <code>
   213 <code>
   214 In []: marks = [10, 20, 30, 50, 55, 75, 83]
   214 In []: marks = [10, 20, 30, 50, 55, 75, 83]
   215 </code>
   215 </code>
   216 <time_limit>
   216 <time_limit>
   217 30
   217 45
   218 </time_limit>
   218 </time_limit>
   219 <expected_answer>
   219 <expected_answer>
   220 array \( marks \)
   220 array \( marks \)
   221 </expected_answer>
   221 </expected_answer>
   222 </question>
   222 </question>
   230 In []: a = array([[1, 2],
   230 In []: a = array([[1, 2],
   231                   [3, 4]])
   231                   [3, 4]])
   232 In []: a[1,0] = 0
   232 In []: a[1,0] = 0
   233 </code>
   233 </code>
   234 <time_limit>
   234 <time_limit>
   235 60
   235 75
   236 </time_limit>
   236 </time_limit>
   237 <expected_answer>
   237 <expected_answer>
   238 \[ \[ 1 , 2 \] , \[ 0 , 4 \] \]
   238 \[ \[ 1 , 2 \] , \[ 0 , 4 \] \]
   239 </expected_answer>
   239 </expected_answer>
   240 </question>
   240 </question>
   265 <topic>Arrays and Matrices</topic>
   265 <topic>Arrays and Matrices</topic>
   266 <description>
   266 <description>
   267 If x = array([[1,2,3,4]]) How to change x to array([[1,2,0,4]]) ?
   267 If x = array([[1,2,3,4]]) How to change x to array([[1,2,0,4]]) ?
   268 </description>
   268 </description>
   269 <time_limit>
   269 <time_limit>
   270 60
   270 75
   271 </time_limit>
   271 </time_limit>
   272 <expected_answer>
   272 <expected_answer>
   273 x\[ 0 \]\[ 2 \] = 0
   273 x\[ 0 \]\[ 2 \] = 0
   274 </expected_answer>
   274 </expected_answer>
   275 </question>
   275 </question>
   286 array([[2,3],
   286 array([[2,3],
   287       [4,2]])
   287       [4,2]])
   288        
   288        
   289 </description>
   289 </description>
   290 <time_limit>
   290 <time_limit>
   291 60
   291 90
   292 </time_limit>
   292 </time_limit>
   293 <expected_answer>
   293 <expected_answer>
   294 x\[ \: , 1 \: 3 \]
   294 x\[ \: , 1 \: 3 \]
   295 x\[ \: , 1 \: -1 \]
   295 x\[ \: , 1 \: -1 \]
   296 x\[ \: , -3 \: -1 \]
   296 x\[ \: , -3 \: -1 \]
   306 In []: x = array([[9,18,27],
   306 In []: x = array([[9,18,27],
   307                   [30,60,90],
   307                   [30,60,90],
   308                   [14,7,1]])
   308                   [14,7,1]])
   309 </code>
   309 </code>
   310 <time_limit>
   310 <time_limit>
   311 30
   311 60
   312 </time_limit>
   312 </time_limit>
   313 <expected_answer>
   313 <expected_answer>
   314 9
   314 9
   315 </expected_answer>
   315 </expected_answer>
   316 </question>
   316 </question>
   323 <code>
   323 <code>
   324 In []: a = array([[1, 2],
   324 In []: a = array([[1, 2],
   325                   [3, 4]])
   325                   [3, 4]])
   326 </code>
   326 </code>
   327 <time_limit>
   327 <time_limit>
   328 30
   328 45
   329 </time_limit>
   329 </time_limit>
   330 <expected_answer>
   330 <expected_answer>
   331 a\.T
   331 a\.T
   332 </expected_answer>
   332 </expected_answer>
   333 </question>
   333 </question>
   357 <topic>Arrays and Matrices</topic>
   357 <topic>Arrays and Matrices</topic>
   358 <description>
   358 <description>
   359 What command do you use to find the inverse of a matrix and its eigenvalues?
   359 What command do you use to find the inverse of a matrix and its eigenvalues?
   360 </description>
   360 </description>
   361 <time_limit>
   361 <time_limit>
   362 30
   362 45
   363 </time_limit>
   363 </time_limit>
   364 <expected_answer>
   364 <expected_answer>
   365 inv .* eigvals
   365 inv .* eigvals
   366 </expected_answer>
   366 </expected_answer>
   367 </question>
   367 </question>
   370 <topic>Solving linear equations</topic>
   370 <topic>Solving linear equations</topic>
   371 <description>
   371 <description>
   372 Given a 4x4 matrix A and a 4-vector b , what command do you use to solve for the equation Ax = b ?
   372 Given a 4x4 matrix A and a 4-vector b , what command do you use to solve for the equation Ax = b ?
   373 </description>
   373 </description>
   374 <time_limit>
   374 <time_limit>
   375 45
   375 60
   376 </time_limit>
   376 </time_limit>
   377 <expected_answer>
   377 <expected_answer>
   378 solve \( A , b \)
   378 solve \( A , b \)
   379 </expected_answer>
   379 </expected_answer>
   380 </question>
   380 </question>
   383 <topic>Finding roots</topic>
   383 <topic>Finding roots</topic>
   384 <description>
   384 <description>
   385 How do you calculate the roots of the polynomial, y = 1 + 6*x + 8*x^2 + x^3 
   385 How do you calculate the roots of the polynomial, y = 1 + 6*x + 8*x^2 + x^3 
   386 </description>
   386 </description>
   387 <time_limit>
   387 <time_limit>
   388 45
   388 75
   389 </time_limit>
   389 </time_limit>
   390 <expected_answer>
   390 <expected_answer>
   391 roots \( \[ 1 , 8 , 6 , 1 \] \)
   391 roots \( \[ 1 , 8 , 6 , 1 \] \)
   392 </expected_answer>
   392 </expected_answer>
   393 </question>
   393 </question>
   396 <topic>Solving linear equations</topic>
   396 <topic>Solving linear equations</topic>
   397 <description>
   397 <description>
   398 Two arrays a and b are numerically almost equal, what command do you use to check if this is true?
   398 Two arrays a and b are numerically almost equal, what command do you use to check if this is true?
   399 </description>
   399 </description>
   400 <time_limit>
   400 <time_limit>
   401 30
   401 60
   402 </time_limit>
   402 </time_limit>
   403 <expected_answer>
   403 <expected_answer>
   404 allclose \( a , b \)
   404 allclose \( a , b \)
   405 allclose \( b , a \)
   405 allclose \( b , a \)
   406 </expected_answer>
   406 </expected_answer>
   410 <topic>Basic Datatypes</topic>
   410 <topic>Basic Datatypes</topic>
   411 <description>
   411 <description>
   412 What is the largest integer value that can be represented by Python?
   412 What is the largest integer value that can be represented by Python?
   413 </description>
   413 </description>
   414 <time_limit>
   414 <time_limit>
   415 30
   415 45
   416 </time_limit>
   416 </time_limit>
   417 <options>
   417 <options>
   418 No Limit
   418 No Limit
   419 2**32
   419 2**32
   420 2**32 - 1
   420 2**32 - 1
   429 <topic>Basic Datatypes</topic>
   429 <topic>Basic Datatypes</topic>
   430 <description>
   430 <description>
   431 What is the result of 17.0 / 2?
   431 What is the result of 17.0 / 2?
   432 </description>
   432 </description>
   433 <time_limit>
   433 <time_limit>
   434 15
   434 45
   435 </time_limit>
   435 </time_limit>
   436 <expected_answer>
   436 <expected_answer>
   437 8.5
   437 8.5
   438 </expected_answer>
   438 </expected_answer>
   439 </question>
   439 </question>
   442 <topic>Basic Datatypes</topic>
   442 <topic>Basic Datatypes</topic>
   443 <description>
   443 <description>
   444 Which of the following is not a type in Python?
   444 Which of the following is not a type in Python?
   445 </description>
   445 </description>
   446 <time_limit>
   446 <time_limit>
   447 30
   447 45
   448 </time_limit>
   448 </time_limit>
   449 <options>
   449 <options>
   450 int
   450 int
   451 float
   451 float
   452 char
   452 char
   462 <topic>Basic Datatypes</topic>
   462 <topic>Basic Datatypes</topic>
   463 <description>
   463 <description>
   464 How do you create a complex number with real part 2 and imaginary part 0.5 ?
   464 How do you create a complex number with real part 2 and imaginary part 0.5 ?
   465 </description>
   465 </description>
   466 <time_limit>
   466 <time_limit>
   467 30
   467 45
   468 </time_limit>
   468 </time_limit>
   469 <expected_answer>
   469 <expected_answer>
   470 2 \+ 0\.5j
   470 2 \+ 0\.5j
   471 complex \( 2 , 0\.5 \)
   471 complex \( 2 , 0\.5 \)
   472 </expected_answer>
   472 </expected_answer>
   476 <topic>Input and Output</topic>
   476 <topic>Input and Output</topic>
   477 <description>
   477 <description>
   478 What is the difference between print x and print x,
   478 What is the difference between print x and print x,
   479 </description>
   479 </description>
   480 <time_limit>
   480 <time_limit>
   481 30
   481 75
   482 </time_limit>
   482 </time_limit>
   483 <expected_answer>
   483 <expected_answer>
   484 correct manually
   484 correct manually
   485 </expected_answer>
   485 </expected_answer>
   486 </question>
   486 </question>
   489 <topic>Input and Output</topic>
   489 <topic>Input and Output</topic>
   490 <description>
   490 <description>
   491 What does 't' * 40 produce?
   491 What does 't' * 40 produce?
   492 </description>
   492 </description>
   493 <time_limit>
   493 <time_limit>
   494 30
   494 45
   495 </time_limit>
   495 </time_limit>
   496 <options>
   496 <options>
   497 40
   497 40
   498 tttttttttttttttttttttttttttttttttttttttt
   498 tttttttttttttttttttttttttttttttttttttttt
   499 t40
   499 t40
   528 </description>
   528 </description>
   529 <code>
   529 <code>
   530 In []: 47 % 3 
   530 In []: 47 % 3 
   531 </code>
   531 </code>
   532 <time_limit>
   532 <time_limit>
   533 45
   533 60
   534 </time_limit>
   534 </time_limit>
   535 <expected_answer>
   535 <expected_answer>
   536 2
   536 2
   537 </expected_answer>
   537 </expected_answer>
   538 </question>
   538 </question>
   541 <topic>Lists and Tuples</topic>
   541 <topic>Lists and Tuples</topic>
   542 <description>
   542 <description>
   543 How do you find the presence of an element x in the list a
   543 How do you find the presence of an element x in the list a
   544 </description>
   544 </description>
   545 <time_limit>
   545 <time_limit>
   546 30
   546 60
   547 </time_limit>
   547 </time_limit>
   548 <expected_answer>
   548 <expected_answer>
   549 x in a
   549 x in a
   550 </expected_answer>
   550 </expected_answer>
   551 </question>
   551 </question>
   557 </description>
   557 </description>
   558 <code>
   558 <code>
   559 In []: set([1, 2, 8, 2, 13, 8, 9])
   559 In []: set([1, 2, 8, 2, 13, 8, 9])
   560 </code>
   560 </code>
   561 <time_limit>
   561 <time_limit>
   562 45
   562 75
   563 </time_limit>
   563 </time_limit>
   564 <expected_answer>
   564 <expected_answer>
   565 set \( \[ 1 , 2 , 8 , 13 , 9 \] \)
   565 set \( \[ 1 , 2 , 8 , 13 , 9 \] \)
   566 \[ 1 , 2 , 8 , 13 , 9 \]
   566 \[ 1 , 2 , 8 , 13 , 9 \]
   567 </expected_answer>
   567 </expected_answer>
   576 In []: a = {'a': 1, 'b': 2} 
   576 In []: a = {'a': 1, 'b': 2} 
   577 In []: a['a'] = 10
   577 In []: a['a'] = 10
   578 In []: print a
   578 In []: print a
   579 </code>
   579 </code>
   580 <time_limit>
   580 <time_limit>
   581 60
   581 75
   582 </time_limit>
   582 </time_limit>
   583 <expected_answer>
   583 <expected_answer>
   584 \{ \'a\' \: 10 , \'b\' \: 2 \}
   584 \{ \'a\' \: 10 , \'b\' \: 2 \}
   585 \{ \'a\' \: 10 , \"b\" \: 2 \}
   585 \{ \'a\' \: 10 , \"b\" \: 2 \}
   586 \{ \"a\" \: 10 , \"b\" \: 2 \}
   586 \{ \"a\" \: 10 , \"b\" \: 2 \}
   596 <code>
   596 <code>
   597 In []: a = [1, 2, 3] 
   597 In []: a = [1, 2, 3] 
   598 In []: a.extend([5, 6])
   598 In []: a.extend([5, 6])
   599 </code>
   599 </code>
   600 <time_limit>
   600 <time_limit>
   601 45
   601 75
   602 </time_limit>
   602 </time_limit>
   603 <expected_answer>
   603 <expected_answer>
   604 \[ 1 , 2 , 3 , 5 , 6 \]
   604 \[ 1 , 2 , 3 , 5 , 6 \]
   605 </expected_answer>
   605 </expected_answer>
   606 </question>
   606 </question>
   613 <code>
   613 <code>
   614 In []: a = (1, 2, 3)
   614 In []: a = (1, 2, 3)
   615 In []: a[1] = 10
   615 In []: a[1] = 10
   616 </code>
   616 </code>
   617 <time_limit>
   617 <time_limit>
   618 30
   618 60
   619 </time_limit>
   619 </time_limit>
   620 <expected_answer>
   620 <expected_answer>
   621 error
   621 error
   622 Error
   622 Error
   623 ERROR
   623 ERROR
   632 <code>
   632 <code>
   633 def func(x, y=10):
   633 def func(x, y=10):
   634     print x+1, y+10
   634     print x+1, y+10
   635 </code>
   635 </code>
   636 <time_limit>
   636 <time_limit>
   637 60
   637 90
   638 </time_limit>
   638 </time_limit>
   639 <expected_answer>
   639 <expected_answer>
   640 2 20
   640 2 20
   641 </expected_answer>
   641 </expected_answer>
   642 </question>
   642 </question>
   645 <topic>Functions</topic>
   645 <topic>Functions</topic>
   646 <description>
   646 <description>
   647 How many items can a function return ?
   647 How many items can a function return ?
   648 </description>
   648 </description>
   649 <time_limit>
   649 <time_limit>
   650 30
   650 45
   651 </time_limit>
   651 </time_limit>
   652 <options>
   652 <options>
   653 One
   653 One
   654 Multiple
   654 Multiple
   655 Two
   655 Two