Write a Python program to create a set, add member(s) in a set and remove one item from set.
createset.py
num={10,50,60,40,20,30,80}
print("Set is created as :",num)
a=int(input("Enter the number to add into set :"))
num.add(a)
print("After adding set is :",num)
b=int(input("Enter the number to remove from set :"))
num.remove(b)
print("After removing set is :",num)
Output
Question 2
Write a Python program to perform following operations on set: intersection of sets, union of sets, set difference, symmetric difference, clear a set.
operations.py
set1={10,50,60,40,20,30,80}
set2={20,60,70,8,30,10,23,90}
print("Set1 is created as :",set1)
print("Set2 is created as :",set2)
print("Union of set1 and set2 is :",set1|set2)
print("Intersection of set1 and set2 is :",set1&set2)
print("Difference of set1 and set2 is :",set1-set2)
print("Symmetric difference of set1 and set2 is :",set1^set2)
set1.clear()
print("After clearing set1 is :",set1)
Output
Question 3
Write a Python program to find maximum and the minimum value in a set.
minmax.py
num={10,50,60,40,20,30,80}
print("Created set is :",num)
print("Minimum value in set is :",min(num))
print("Maximum value in set is :",max(num))
Output
Question 4
Write a Python program to find the length of a set.
length.py
num={10,50,60,40,20,30,80}
print("Created set is :",num)
print("Length of set is :",len(num))