CodeSolved

Solved Programming Questions & Exercises

Subscription and community of two sets

Practice Easy 1744/ Download 545 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

6 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}")
set1 = set(input("Enter Number1 : "))
set2 = set(input("Enter Number2 : "))
union_set = set1.union(set2)
intersection_set = set1.intersection(set2)

print(f"union : {union_set}")
print(f"intersection : {intersection_set}")
User 4207 Download Python
def input_set():
    # Receive a collection from the user
    elements = input("عناصر مجموعه را با فاصله از هم وارد کنید: ").split()
    return set(elements)

def main():
    print("مجموعه اول:")
    set_a = input_set()

    print("\nمجموعه دوم:")
    set_b = input_set()

    # Subscription calculation
    intersection = set_a & set_b
    # Community calculation
    union = set_a | set_b

    print("\nنتایج:")
    print(f"اشتراک دو مجموعه: {intersection}")
    print(f"اجتماع دو مجموعه: {union}")

if __name__ == "__main__":
    main()

Submit answer

Submitting answers is currently unavailable.

×
×
Close