You are on page 1of 5

EX NO: 7 a.

OPERATIONS ON SET
DATE: LANGUAGE
AIM:
To write a python program to implement operations in a set using components of a
Language.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare two sets with components of language in it.
Step 3: Do the set operations union, intersection, difference and symmetric difference.
Step 4: Display the result.
Step 5: Stop the program.
PROGRAM:
L1={'Pitch','Syllabus','Script','Grammar','Sentences'}
L2={'Grammar','Syllabus','Context','Words','Phonetics'}
#set Union
print("Union of L1 and L2 is",L1|L2)
#set Intersection
print("Intersection of L1 and L2",L1&L2)
#set difference
print("Difference of L1 and L2 is",L1-L2)
#set symmetric difference
print("Symmetric Difference of L1 an L2 is",L1^L2)
OUTPUT:
Union of L1 and L2 is {'Syllabus', 'Script', 'Words', 'Context', 'Phonetics', 'Pitch', 'Grammar',
'Sentences'}
Intersection of L1 and L2 {'Grammar', 'Syllabus'}
Difference of L1 and L2 is {'Script', 'Sentences', 'Pitch'}
Symmetric Difference of L1 an L2 is {'Phonetics', 'Pitch', 'Script', 'Words', 'Context',
'Sentences'}
RESULT:
Thus, the above program was successfully executed and verified.
EX NO: 7 b. OPERATIONS ON SET
DATE: COMPONENTS OF AN AUTOMOBILE
AIM:
To write a python program to implement operations on an automobile set.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare set variables car and motorbike to list the components of a car and
motorbike.
Step 3: Do the set operations union, intersection, difference and symmetric difference.
Step 4: Display the result.
Step 5: Stop the program.
PROGRAM:
#declaring a set of Components of a car
car = {'Engine','Battery','Alternator','Radiator','Steering','Break','Seat Belt'}
#declaring a set of Components of a motorbike
motorbike={'Engine','Fuel tank','Wheels','Gear','Break'}
#Elements of the set car
print('Components of Car: ',car)
#Elements of the set motorbike
print('Components of motorbike: ',motorbike)
#union operation
print('Union of car and motorbike: ',car | motorbike)
#intersection operation
print('Intersection of car and motorbike: ',car & motorbike)
#difference operation
print('Difference operation: ', car - motorbike)
#Symmetric difference
print('Symmetric difference operation: ',car ^ motorbike)
OUTPUT:
Components of Car: {'Battery', 'Seat Belt', 'Engine', 'Radiator', 'Break', 'Alternator', 'Steering'}
Components of motorbike: {'Fuel tank', 'Engine', 'Gear', 'Wheels', 'Break'}
Union of car and motorbike: {'Fuel tank', 'Engine', 'Radiator', 'Seat Belt', 'Break', 'Alternator',
'Steering', 'Battery', 'Gear', 'Wheels'}
Intersection of car and motorbike: {'Break', 'Engine'}
Difference operation: {'Radiator', 'Seat Belt', 'Alternator', 'Steering', 'Battery'}
Symmetric difference operation: {'Fuel tank', 'Radiator', 'Seat Belt', 'Alternator', 'Steering',
'Battery', 'Gear', 'Wheels'}
RESULT:
Thus, the above program was successfully executed and verified.
EX.NO: 7 c. OPERATIONS ON DICTIONARY
DATE: ELEMENTS OF A CIVIL STRUCTURE
AIM:
To write a python program to implement operations on elements of a civil structure
dictionary.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare a dictionary building to list the elements of a civil structure.
Step 3: Do the dictionary operations add, update, pop and length.
Step 4: Display the result.
Step 5: Stop the program.
PROGRAM:
#declare a dictionary building
building={1:'foundation',2:'floor',3:'beams',4:'columns',5:'roof',6:'stair'}
#Elements in dictionary
print('Elements in dictionary building: ',building)
#length of a dictionary
print('Length of the dictionary building: ',len(building))
#value of the key 5
print('The value of the key 5',building.get(5))
#update key 6 :stair as lift
building.update({6:'lift'})
print('After updation of stair as lift: ',building)
#Add element window in the dictionary
building[7]='window'
print('After adding window: ',building)
#using pop operation to remove element
building.pop(3)
print('After removing element beams from building: ',building)
OUTPUT:
Elements in dictionary building: {1: 'foundation', 2: 'floor', 3: 'beams', 4: 'columns', 5: 'roof',
6: 'stair'}
Length of the dictionary building: 6
The value of the key 5 roof
After updation of stair as lift: {1: 'foundation', 2: 'floor', 3: 'beams', 4: 'columns', 5: 'roof', 6:
'lift'}
After adding window: {1: 'foundation', 2: 'floor', 3: 'beams', 4: 'columns', 5: 'roof', 6: 'lift', 7:
'window'}
After removing element beams from building: {1: 'foundation', 2: 'floor', 4: 'columns', 5: 'roof',
6: 'lift', 7: 'window'}
RESULT:
Thus, the above program was successfully executed and verified.

You might also like