Directions. Name your scripts 253-yourlastname-?-?.py . For example, my submission for P3 problem 4 would be a file 253-pauli-3-4.py . Each project script should be uploaded to Canvas by clicking the assignment. The Python Tutorial (PT) is available at
http://docs.python.org/py3k/tutorial/
the Non-Programmers Tutorial for Python 3 (NP) is available at http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3
(1) (PT) Read and work through the examples in 3.1.3: Lists
5.1.3: List Comprehensions
5.4.: Sets
(2) (NP) Read and work through the examples in
Lists
(3) Write a script that contains the following. For each part, first print the number to
make it easier to grade.
(a) A function is_subset(A,B) that for two sets A and B returns True if A B
and False otherwise. Use a for loop and in but not the build-in <=.
(b) A function is_proper_subset(A,B) that for two sets A and B returns True if
A B and False otherwise. Use a for loop and in but not the build-in <.
(c) Verification whether your functions work correctly by using them to determine whether the following are true or false. Use set comprehensions to construct sets
given in set builder notation. (i)
(ii)
(iii) {1, 2, 3} (iv) {1,2,3}
(v) {1,2,3} {1,2,3} (vi) {1,2,3} {1,2,3}
(vii) {1,4} {x2 | x {1,2,3,...,20}}
(viii) {4,10}{x|x{1,2,3,...,50}xmod3=1}
(ix) {x2 |x{1,2,3,...,50}xmod3=0}{3,81}
(4) Write a script that contains the following. For each part, first print the number to
make it easier to grade.
(a) A function cartesian_product(A, B) that returns the cartesian product of two
sets A and B. You can represent the tuple (a, b) either as a tuple or a list with
two elements.
(b) Verification whether your functions works correctly by using them to compute
the following cartesian products: (i) {1,2,3}{5,6}
(ii) {1, 2} {2}
(iii) {7}{1,2,3,4}
(iv) {1,2,3,4}
(v) {1,2,3,...,40}{1,2}
