0% found this document useful (0 votes)
89 views5 pages

Experiment No 1

The document describes an experiment involving set operations on student data, where students are divided into groups for different activities, and defines functions to calculate sets of students based on their activities, such as those playing both cricket and badminton. It includes the objectives, problem statement, requirements, theory of basic set operations, and algorithm for implementing the set operation functions on the student data.

Uploaded by

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

Experiment No 1

The document describes an experiment involving set operations on student data, where students are divided into groups for different activities, and defines functions to calculate sets of students based on their activities, such as those playing both cricket and badminton. It includes the objectives, problem statement, requirements, theory of basic set operations, and algorithm for implementing the set operation functions on the student data.

Uploaded by

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

Experiment No-01(Group A)

Title:- Set Operations


Objectives:-
1. Understand the implementation of array data structure.
2. Understand the implementation of set with various operations like union,
intersection, difference and symmetric difference.

Problem Statement:-
In second year computer engineering class, group A student’s play cricket, group Bstudents
play badminton and group C students play football.
Write a Python program using functions to compute following: -
a) List of students who play both cricket and badminton
b) List of students who play either cricket or badminton but not both
c) Number of students who play neither cricket nor badminton
d) Number of students who play cricket and football but not badminton.
(Note- While realizing the group, duplicate entries should be avoided, Do not use SET
built-in functions)

Software and Hardware requirements:-


1. Operating system: Linux- Ubuntu 16.04 to 17.10, or Windows 7 to 10,
2. RAM- 2GB RAM (4GB preferable)
3. You have to install Python3 or higher version

Theory- Basic Set operations:-


Sets can be used to carry out mathematical set operations like union, intersection,
difference and symmetric difference. We can do this with operators or methods.
1. Set Union:-
This method performs the union operation on two or more Python sets. What it does is
it returns all the items that are in any of those sets.
Union is performed using | operator. Same can be accomplished using the method
union().

>>>A = {1, 2, 3, 4, 5}
>>>B = {4, 5, 6, 7, 8}
>>>print(A | B) # OR by using union()
>>>print(A.union(B)) # output of both will be same {1, 2, 3, 4, 5, 6, 7, 8}
2. Set Intersection:-
This method takes as argument sets, and returns the common items in all the sets.
Intersection is performed using & operator. Same can be accomplished using the
method intersection().
>>>A = {1, 2, 3, 4, 5}
>>>B = {4, 5, 6, 7, 8}
>>>print(A & B) # OR by using intersection()
>>>print(A.intersection(B)) # output of both will be same {4, 5}

3. Set Difference
The difference() method returns the difference of two or more sets. It returns
as a set.
Difference of A and B (A - B) is a set of elements that are only in A but not in
B. Similarly, B - A is a set of element in B but not in A.
Difference is performed using - operator. Same can be accomplished using the
method difference().

>>>A = {1, 2, 3, 4, 5}
>>>B = {4, 5, 6, 7, 8}
>>>print(A - B) # OR by using difference()
>>>print(A.difference(B)) # output of both will be same {1, 2, 3}

4. Set Symmetric Difference


This method returns all the items that are unique to each set.
Symmetric Difference of A and B is a set of elements in both A and B except those
that are common in both.
Symmetric difference is performed using ^ operator. Same can be accomplished using
the method symmetric_difference().

>>>A = {1, 2, 3, 4, 5}
>>>B = {4, 5, 6, 7, 8}
>>>print(A ^ B) # OR by using symmetric_difference()
>>>print(A.symmetric_difference(B)) # output of both will be same {1, 2, 3, 6, 7, 8}
Algorithm:-
1) Start.
2) Declare variables such as SEComp,Cricket,Football,Badminton,ch.
3) Input no of student in SEComp along with their names.
4) Input no.of students playing Cricket along with their names
5) Input no of students playing Football along with their names
6) Input no of students playing Badminton along with their names.
7) Print menu 1) List of student who plays cricket and badminton.
2) List of student who plays either cricket or badminton but not both.
3) List of student who plays neither cricket nor badminton.
4) No. of student who plays cricket and football but not badminton.
5) Exit.
ch=Input Enter your choice
8) If ch==1 then call function CB
Input value of a do you want to continue (y/n).
If a==’y’ then go to step 7.
else,thank you for using program.
9) else if ch==2,then call function eCeB
Input value of a do you want to continue (y/n).
If a==’y’ then go to step 7.
else ,thank you for using program.
10) else if ch==3 then call function nCnB.
Input value of a, do you want to continue (y/n).
If a==’y’ then go to step 7.
else, thank you for using program.
11) else if ch==4 then call function CFnB
Input value of a , do you want to continue (y/n).
If a==’y’ ,then go to step 7.
else,thank you for using program.
12) else if ch==5 then ,go to step 13.
else,print wrong choice .
Input value of a, do you want to continue (y/n)
if a==’y’ then go to step 7.
else,thank you for using program.
13) Stop.
Start

Flowchart:-
Declare variables such as SEComp,Cricket,Football,Badminton,ch,a

Input no of student in SEComp along with their names.


Input no.of students playing Cricket along with their names
Input no of students playing Football along with their names
Input no of students playing Badminton along with their names.

Print menu 1) List of student who plays cricket and badminton.


2) List of student who plays either cricket or badminton but not both.
3) List of student who plays neither cricket nor badminton.
4) No. of student who plays cricket and football but not badminton.
5) Exit. ch=Input Enter your choice

Yes
if ch === 1 CB(Cricket,Badmiton)

a=Input value of a do you want to continue (y/n).


No

Yes No
thank you for
if a === ‘y’
using program.

Yes
if ch === 2 eCeB(Cricket,Badmiton)

No
a=Input value of a do you want to continue (y/n).

Yes No thank you for


if a === ‘y’ using program.

Yes
if ch === 3
nCnB(Cricket,Badmiton)

No
a=Input value of a do you want to continue
(y/n).

Yes No thank you for


if a === ‘y’
using program.

Yes
if ch ===4
CFnB(Cricket,Footbal ,Badmiton)

No
a=Input value of a do you want to continue (y/n).

Yes No thank you for


if a === ‘y’ using program.
No
if ch === 5
print wrong choice .

Yes a=Input value of a do you want to continue (y/n).

Yes No
if a === ‘y’ thank you for
using program.
Stop
Conclusion:
By this way, we can learn how to implement various set operations.

You might also like