Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below, you will find two lists of functions that you may code. You will choose two functions from the first list ( i . e

Below, you will find two lists of functions that you may code. You will choose two functions
from the first list (i.e. the "Set Construction" list) and one function from the second list (i.e.
the "Set Relations" list). So you will be creating three functions in all. Note that all sets
will be represented by lists in Python with no repeated elements. Also note that there is
a way you can construct sets in Python without using lists. For this assignment,
you are not allowed to use this construction in any way.
Set Construction.
(a) Create a function called "intersect" whose inputs are two sets (lists) A and B,
and whose output is a set (list) that is the intersection AB of the two sets.
(b) Create a function called "union" whose inputs are two sets (lists) A and B, and
whose output is a set (list) that is the union AB of the two sets.
(c) Create a function called "difference" whose inputs are two sets (lists) A and B,
and whose output is a set (list) that is the set difference (i.e. "set-minus")A??B
of the two sets.
(d) Create a function called "cartesianProduct" whose inputs are two sets (lists)A
and B, and whose output is a set (list) that is the Cartesian product AB
of the two sets. Note that ordered pairs will be represented by lists with two
components.
Set Relations
(a) Create a function called "subset" whose inputs are two sets (lists) A and B, and
whose output is a Boolean value. The output is "True" if AsubeB and "False" if
AB.
(b) Create a function called "equal" whose inputs are two sets (lists) A and B, and
whose output is a Boolean value. The output is "True" if A=B and "False" if
AB. Note that even if A=B, the elements may be listed in a different order.
(c) Create a function called "element" whose inputs are a set (list) A and some object.
x, and whose output is a Boolean value. The output is "True" if xinA and "False"
if x!inA.
Make sure your function is well documented. You should have one-line comments (using the
single line comments with #) written in complete sentences that describe what each line of
code does. You may not import any packages to help you with your function.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago

Question

1. Identify and control your anxieties

Answered: 1 week ago