2.4. Answers#

Solution to Exercise 2.1

  1. 1.0 (float)

  2. 1 (int)

  3. TypeError since x/x is a float and we cannot index an array using a float. Try using z[x//x] or z[int(x/x)] instead.

  4. "5555555555" (string)

  5. [10, 20, 10, 20, 10, 20, ... , 10, 20] (list)

  6. TypeError since 10. is a float and we cannot use the operator * with a list and a float. First convert to a float.

  7. array(100, 200) (Numpy array)

  8. TypeError since floats and strings cannot be added. Convert w to an int or float first e.g. y + int(w).

  9. array([100, 400]) Numpy performs elementwise multiplication