Exercise 202
Write a program in python as a function which examines whether two sets are disjoint or not. If the two sets are disjoint, the function must return True and False if not.
Solution
def examineSet(E , F):
# using and initializing a counter
counter = 0
# we test if there is a common element of E and F and incrementing the counter
for x in E:
if x in F:
counter +=1
if counter > 0:
return True
else:
return False
# Testing algorithm
E = {"Java", "Python", "Javascript", "C ++", "C #"}
F = {"VB.ET", "Java", "Kotlin", "Python"}
print(examineSet(E , F)) # display True
G = {"Zend Framework", "Django", "Flask"}
H = {"AngularJS", "Ionic Framework" , "ReactJS"}
print(examineSet(G , H)) # display False
Younes Derfoufi
my-courses.net
my-courses.net