You are on page 1of 1

Student Name:

Student Number:
CS 104 – Spring 2022

QUIZ 5
1. (50pts) Write a Python program that compares two lists and finds the different
unique elements in these lists. The result should be stored in the list as well. You
can assume the given lists are:
list1 = [1,5,7,9,19,21,6, 2, 7]
list2 = [2,3,5,6,12,7,1]

list1 = [1,5,7,9,19,21,6, 2, 7]
list2 = [2,3,5,6,12,7,1]

uniqueList = []

for i in list1 + list2:


if (i in list1 and i not in list2) or (i in list2 and i not in list1):
uniqueList.append(i)

print(uniqueList)

2. (50pts) Write a function which takes a value and returns whether that
value is in the gray zone or not for the given two sets below:
A = { 2, 3, 4, 5, 6, 7, 8}
B = {7, 8, 9, 10}

def setFunc(value):
A = set([2, 3, 4, 5, 6, 7, 8])
B = set([7, 8, 9, 10])
return value not in (A | B) - (A & B)

# pick a random value: e.g., 2, expect False


result = setFunc (2)
print(result)

# pick a random value: e.g., 7, expect True


result = setFunc (7)
print(result)

You might also like