I have 2 defined sets they are
set1 = {1, 2, 3}
set2 = {1, 3, 4, 6}
and I have 2 fucntions. One for add a value to sets and one for print it
def printSet():
x = input("Enter name of the set\n")
if x in globals():
anySet = set(globals()[x])
result = print("Your set is:\n", anySet)
else:
result = print("ERROR")
return result
def addSet():
x = input("Enter name of the set\n")
if x in globals():
anySet = set(globals()[x])
print("Your set is:\n", anySet)
y = int(input("Enter the value that you want to add to the set\n"))
anySet.add(y)
result = print("Your new set is:\n", anySet)
else:
result = print("ERROR")
return result
Let's say i add the value "4" to the set1. When I print it in the fucntion the answer is
Your new set is:
{1, 2, 3, 4}
That is okey but after the line I execute addSet fucntion, if I try to print set1 with
print(set1)
set1 is not being updated and the output is
{1, 2, 3}
How can I fix this problem