Reference no: EM132379446
Assignment -
Directions - Name your scripts 253-yourlastname-?-?.py. For example, my submission for P3 problem 4 would be a file 253-pauli-3-4.py.
(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
(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} Λ x mod 3 = 1}
(ix) {x2|x ∈ {1, 2, 3, . . . , 50} Λ x mod 3 = 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} x {5, 6}
(ii) {1, 2} x {2}
(iii) {7} x {1, 2, 3, 4}
(iv) ∅ x {1, 2, 3, 4}
(v) {1, 2, 3, . . . , 40} x {1, 2}
Attachment:- Assignment File.rar