Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use sets in python to demonstrate the following problems: Suppose a list A conta

ID: 674926 • Letter: U

Question

Use sets in python to demonstrate the following problems:

Suppose a list A contains the 30 students in a mathematics class, and a list B contains the 35 students

in an English class, and suppose there are 20 names on both lists.

Find the number of students: (a) only on list A, (b) only on list B, (c) on list A or B (or both),

(d) on exactly one list.

LetU={1,2,...,9}be the universal set and let

A = {1,2,3,4,5}, C = {5,6,7,8,9}, E = {2,4,6,8},

B = {4,5,6,7}, D = {1,3,5,7,9}, F = {1,5,9}.

Find: (a)AB and AB; (b)AC and AC; (c)DF and DF.

Explanation / Answer

countA = 0
for item in list_A:
if item not in list_B:
countA = countA+1
  
countB = 0
for item in list_B:
if item not in list_A:
countB = countB+1
  

countAB = countA+countB
for item in list_A:
if item in list_B:
countAB = countAB+1
  

countExactly = countA+countB

AUB = {1,2,3,4,5,6,7}

AB = {4,5}

AUC = {1,2,3,4,5,6,7,8,9}

AC = {5}

DUF = {1,3,5,7,9}

DF = {1,5,9}