What does repr stand for?
repr is fundamental function calling objects __repr__ method. The basic idea of the function is to be string representation of object, which would produce copy of same object if evaluated.
What does repr stand for?
repr is fundamental function calling objects __repr__ method. The basic idea of the function is to be string representation of object, which would produce copy of same object if evaluated.
You are still using set at line 3. Use fundamental set definitions. For example union contains all items in first set and items in difference of second and first set.
I'm sorry, that was a copy of my old code. I edited my post and the current code is now up.
def read_set():
stored_set= set(input("Enter the elements of the set(separated with spaces): ").split())
size = len(stored_set)
print ("A set with", size, "elements has been read (repeating items were removed)")
return(stored_set)
def print_set(A):
fixed_set=set()
for element in A:
try:
element=int(element)
fixed_set.add(element)
except ValueError:
print('\n',element,'is not an integer and will not be included in the final set\n')
A=fixed_set
print (A)
return A
def union_set(A,B):
union= A|B
print("\n Union: ", union)
return union
def intersection_set(A,B):
intersection = A&B
print("Intersection: ", intersection)
return intersection
def difference_set(A, B):
difference = A - B
print(" Difference: ", difference)
return difference
def cartprod_set(A, B):
if __name__=="__main__":
print("\nEnter two sets, and i will print the result of some basic set operations on those sets.")
set_one = read_set()
set_two = read_set()
set_one1= set(set_one)
set_two2= set(set_two)
set_one=list(set(set_one))
set_two=list(set(set_two))
print("\nThe two sets you entered are as follows: ")
print_set(set_one)
print_set(set_two)
union_set(set_one1, set_two2)
intersection_set(set_one1, set_two2)
difference_set(set_one1, set_two2)
Enter two sets, and i will print the result of some basic set operations on those sets.
Enter the elements of the set(separated with spaces): 4 5 3 6
A set with 4 elements has been read (repeating items were removed)
Enter the elements of the set(separated with spaces): 4 3 6 4
A set with 3 elements has been read (repeating items were removed)
The two sets you entered are as follows:
{3, 4, 5, 6}
{3, 4, 6}
Union: {'3', '5', '4', '6'}
Intersection: {'3', '4', '6'}
Difference: {'5'}
We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.