[go: up one dir, main page]

0% found this document useful (0 votes)
11 views2 pages

Problem Statement 3

The document outlines a Python program that demonstrates various set operations including union, intersection, difference, and symmetric difference using two sets, A and B. It provides the source code along with the expected output for each operation. The program also checks if one set is a subset or superset of the other.

Uploaded by

adithapa129
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Problem Statement 3

The document outlines a Python program that demonstrates various set operations including union, intersection, difference, and symmetric difference using two sets, A and B. It provides the source code along with the expected output for each operation. The program also checks if one set is a subset or superset of the other.

Uploaded by

adithapa129
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Student name- Sachin Page no-3

Roll no- 48 D.O.P-26/08/2025


Course- BCA AI&DS

PROBLEM STATEMENT 3- Write a python program to implement set operation.

OBJECTIVE- To understand the implementation of various set operation.

EXPLANATION- A set operation is a mathematical action on two or more sets that

Produces a new set by combining, comparing, or modifying the elements of the

original sets.

SOURCE CODE-

# Creating two sets

A = {1, 2, 3, 4, 5}

B = {4, 5, 6, 7, 8}

print("Set A:", A)

print("Set B:", B)

# Union

print("\nUnion of A and B:", A | B) # or A.union(B)

# Intersection

print("Intersection of A and B:", A & B) # or A.intersection(B)

# Difference

print("Difference of A and B (A - B):", A - B) # or A.difference(B)

print("Difference of B and A (B - A):", B - A)

# Symmetric Difference

print("Symmetric Difference of A and B:", A ^ B) # or A.symmetric_difference(B))

# Subset and Superset

print("\nIs A subset of B?", A.issubset(B))

print("Is A superset of B?", A.issuperset(B))


Student name- Sachin Page no-3
Roll no- 48 D.O.P-26/08/2025
Course- BCA AI&DS

OUTPUT-

Set A: {1, 2, 3, 4, 5}

Set B: {4, 5, 6, 7, 8}

Union of A and B: {1, 2, 3, 4, 5, 6, 7, 8}

Intersection of A and B: {4, 5}

Difference of A and B (A - B): {1, 2, 3}

Difference of B and A (B - A): {8, 6, 7}

Symmetric Difference of A and B: {1, 2, 3, 6, 7, 8}

Is A subset of B? False

Is A superset of B? False

You might also like