Hey guys I'm having some trouble with a homework question from Zelles python. I have to make a Set class then test a variety of methods. However my teacher wants us to just use lists and not actually sets. I'm getting an error for the setElements method, it keeps saying I need two arguments but only one given.
class Set:
def setElements (self,elements):
self.set1=list(elements)
def addElement(self,x):
if not x in self.set1:
self.set1.append(x)
def member(self,x):
x in self.set1
def deleteElement(self,x):
self.set1.remove(x)
def intersection(self,set2):
self.set1.intersection(set2)
def union (self,set2):
set1.union(set2)
def subtract(self,set2):
set3 = Set([])
for i in self.elements:
if set2.member(i) == False:
set3.addElement(i)
return set3
def main():
elements= eval(input("Enter a list: "))
set1=Set.setElements(elements)
x=eval(input("Enter a number to add to the set: "))
set1.addElement(x)
x=eval(input("Enter a number to see if it is in the set: "))
print(set1.member(x))
x=eval(input("Enter a number to delete from the set : "))
print(set1)
elements2= list.eval(input("Enter a list: "))
set2=Set.setElements(elements2)
print(intersection(set2))
print(union(set2))
print(subtract(set2))
main()