< Back

Final Exam


If you do not currently have a directory for tests, create one in your cs170 directory, and also create a directory for the final.

$ mkdir ~/cs170/tests
$ mkdir ~/cs170/tests/final
$ cd ~/cs170/test/final

This portion of the test is worth 28 total points. You may only access this webpage, the Python documentation website, and the tkinter documentation website. NO OTHER WEBSITES ARE PERMITTED. As usual, you are not allowed to directly copy any code from the Internet or another individual. You should also follow all coding standards discussed thus far.


Final

Question 10

Create a file called question_10.py in your directory. Inside this file, write a function called cartesian_square(a_list). This function takes a list of values, and returns a list of tuples which represents the cartesian product of a_list with itself.

Cartesian Product of a list A with itself is defined as the list of ALL ordered pairs of the elements from A.

  my_list = [0, 1, 2, 3]
  print(cartesian_square(my_list))
  # [(3, 3), (2, 2), (2, 3), (3, 2), (1, 1), (1, 2), (2, 1), (1, 3),
  #  (3, 1), (0, 0), (0, 1), (1, 0), (0, 2), (2, 0), (0, 3), (3, 0)]

(9 points)


Question 11

Download the file