Set1 and Set2 are the two sets that contain unique integers. Set3 is to be created by taking the union or intersection of Set1 and Set2 using the user defined function Operation(). Perform either union or intersection by reading choice from user. Do not use built in functions union() and intersection() and also the operators “|” and “&“.
set1 = [1,2,3,4,5,6] #Example of a set1
set2 = [1,2,3,5,7,9,10] #Example of a set2
set3 = []
def Operation(choice):
if choice == "union":
for row in set2:
set1.append(row)
for col in set1:
set3.append(col)
elif choice == "intersection":
for row in set1:
if row in set2:
set3.append(row)
for col in set2:
if col in set1:
set3.append(col)
return set(set3)
print(Operation("union"))
Comments
Leave a comment