CodeSolved

Solved Programming Questions & Exercises

Subscription and community of two sets

Practice Easy 1744/ Download 369 Views

Write a program that receives two sets of entry and shows its subscription and community


Help: The two sets are meant to collect members of both A and B sets in one collection without repeating members.
Help: The purpose of subscribing to the two sets is to collect members of both sets A and B that are in both A and B in a collection.


Example:

Receive Input:

Input1: 1,2,3,4
Input2: 3,4,5,6

Output:

1,2,3,4,5,6
3,4

4 Answers

A = {1,2,3,10,11,12,32,33}
B = {1,2,3,14,10,54,354,121}
x = A.union(B)
y = A.intersection(B)
Z = B.union(A)
S = B.intersection(A)
print(f"upaadat(A)=>{x}")
print(f"eshterak(A)==>{y}")
print(f"update (B)=>{Z}")
print(f"eshterak(B)=>{S}")
Hi the answer
Sumy.amiri Download Python
a = {1,2,3,4}
b = {3,4,5,6}
print('community : ',*a.union(b))
print('Subscription :',*a.intersection(b))

set1 = set(map(int, input("input1: ").split(",")))
set2 = set(map(int, input("input2: ").split(",")))
print(",".join(map(str, sorted(set1 | set2))))  # Society
print(",".join(map(str, sorted(set1 & set2))))  # Subscribe

a=set(map(int,input("set1 ").replace(","," ").split()))
b=set(map(int,input("set2 ").replace(","," ").split()))
print(f"union:\n{a|b}")
print(f"unity:\n{a&b}")

Submit answer

Submitting answers is currently unavailable.

×
×
Close