Python Multiple Choice Questions

Mar 12, 2015 • Meredith Durbin

Diagnostic question: data types

Suppose you have the following datasets:

x = ['leopard', 'panther', 'pallas cat']
y = [1, 2, 3, 5, 8, 13]
z = [(1, 1), (4, 4), (9, 9), (16, 16)]

In order, what types of data are these?

  1. List, array, list of arrays
  2. List, list, list of tuples
  3. Array, array, array of tuples
  4. Ambiguous/could be multiple types

Summative question: indexing

Suppose you run the following code:

n = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]
print n[2]

What gets printed?

  1. [6, 5, 4]
  2. 2
  3. 7
  4. [3, 2, 1]

Analysis:

  1. Those who choose (a) understand the structure of the list, but forget that Python indexing starts at 0.
  2. Those who choose (b) fail to understand that n[2] is selecting for the item with index 2 and not the value 2.
  3. Those who choose (c) understand that Python indexing starts at 0, but fail to understand how the list is structured.
  4. Correct