Question: I need help designing a set difference method for sets A and B. I am getting an error saying 'IntSet' object has no attribute 'intersectionset'.
I need help designing a set difference method for sets A and B. I am getting an error saying 'IntSet' object has no attribute 'intersectionset'. I have attached the photo and code below. 
class IntSet(object):
"""An intSet is a set of integers"""
#Information about the implementation (not the abstraction)
#Value of the set is represented by a list of ints, self.vals.
#Each int in the set occurs in self.vals exactly once.
def __init__(self):
"""Create an empty set of integers"""
self.vals = []
def union(self, aset):
"""Finds the union between the current
set and intSet object aset"""
unionset= IntSet()
for i in aset.vals:
unionset.insert(i)
for s in self.vals:
unionset.insert(s)
return unionset
def intersection(self, aset):
"""Finds the intersection between
the current set and intSet object aset"""
intersectionset = IntSet()
for i in self.vals:
if i in self.vals and i in aset.vals:
intersectionset.insert(i)
else:
pass
return intersectionset
def setdifference(self, aset):
"""Find the set difference between the current
set and intSet object aset"""
sdset = IntSet()
self.intersection(aset)
for i in self.intersectionset.vals:
if i in self.intersectionset.vals:
pass
else:
sdset.insert(i)
return sdset.vals
def insert(self, e):
"""Assumes e is an integer and inserts e into self"""
if e not in self.vals:
self.vals.append(e)
def member(self, e):
"""Assumes e is an integer
Returns True if e is in self, and False otherwise"""
return e in self.vals
def remove(self, e):
"""Assumes e is an integer and removes e from self
Raises ValueError if e is not in self"""
try:
self.vals.remove(e)
except:
raise ValueError(str(e) + ' not found')
def getMembers(self):
"""Returns a list containing the elements of self.
Nothing can be assumed about the order of the elements"""
return self.vals[:]
def __str__(self):
"""Returns a string representation of self"""
self.vals.sort()
result = ''
for e in self.vals:
result = result + str(e) + ','
return '{' + result[:-1] + '}' #-1 omits trailing comma
cantor=IntSet()
for i in [2,4,6,8]:
cantor.insert(i)
s = IntSet()
for i in [7,8,9,10,2]:
s.insert(i)
print(cantor)
print(cantor.getMembers())
print(cantor.member(11))
try:
cantor.remove(5)
except ValueError as msg:
print(msg)
25 def intersection(self, aset): 26 27 28 29 30 """Finds the intersection between the current set and intSet object aset""" intersectionset - IntSet() for i in self.vals: if i in self. vals and i in aset.vals: intersectionset.insert(i) 32 else: pass 34 35 36 37 def setdifference (self, aset): 38 39 40 return intersectionset "Find the set difference between the current set and intSet object aset""" sdset - IntSet() self.intersection(aset) for i in self.intersectionset.vals: 42 43 1f 1 in self.intersectionset.vals: pass 45 46 47 48 49 else: sdset.insert(i) return sdset.vals sdset IntSet self.intersection(aset) for i in self.intersectionset.vals: 40 42 43 if i in self.intersectionset.vals: pass AttributeError: 'IntSet' object has no attribute 'intersectionset' In [10]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
