0% found this document useful (0 votes)
134 views

Python programming - Implementing real-time/technical applications using Lists, Tuple Operations(Items present in a library)

Notes prepared about Python programming - Implementing real-time/technical applications using Lists, Tuple Operations(Items present in a library)

Uploaded by

mosesshaam
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)
134 views

Python programming - Implementing real-time/technical applications using Lists, Tuple Operations(Items present in a library)

Notes prepared about Python programming - Implementing real-time/technical applications using Lists, Tuple Operations(Items present in a library)

Uploaded by

mosesshaam
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/ 19

EX.

NO : 4 a Implementing real-time/technical applications using


DATE Lists, Tuple Operations(Items present in a library)

AIM:

To write a Python program for implementing real time/technical library


applications using List and Tuple operations.

ALGORITHM:

STEP 1: Start

STEP 2: Create the variable, inside that variable assigned the list of elements
based on the library using List and Tuple operations
STEP 3: Using array index to print the items using list and Tuple operations

STEP 4: Display the result using output statement

STEP 5: Stop

PROGRAM:
LIST:

library=["books", "author", "barcodenumber" , "price"]


library[0]="ramayanam"
print(library[0])
library[1]="valmiki"
library[2]="python"
library[3]="EG"
print(library)
print (library[:2])
print(library[0:0])
lib=["welcome"]
print(library+lib)
print(library*3)
print(‘s’ in library)
print(min(library))
print(max(library))
print(len(library))
library.append(450)
print(library)
lib.extend([5,6,7])
print(lib)
library.insert(3,4)
library.insert(4,5)
print(library)
library.remove("EG")
print(library)
library.pop(2)
print(library)
library.reverse()
print(library)
print(library.count("valmiki"))
lib.clear()
mylist=lib.copy()
print(mylist)

TUPLE:
tup1 = (12134, 250000)
tup2 = ('books', 'totalprice')
print(tup1[0])

#trying to modify a tuple


tup1[0]='physics' #error
print(tup1)#

mytup=1,2,3 #packing tuples


print(mytup)

mytuple = (1, 2, 3) #unpacking tuples


a, b, c = mytuple
print(a,b,c)

tup3 = tup1 + tup2


print(tup3)

print(tup3[2:])
print(tup3[0:4])
print('petrol' in tup1)
print(10 not in tup1)
print(len(tup3))
print(min(tup1))
print(max(tup1))

import copy
tup1=copy.copy(tup2)
print(tup1)

print(tup2*4)

OUTPUT:
LIST:
Ramayanam
[“ramayanam”, “valmiki”, "python","EG"]
[“ramayanam’,”valmiki”]
[]
[“ramayanam”,”valmiki”, "python","EG",”welcome”]
[“ramayanam”,”valmiki”,"python","EG",“ramayanam”,”valmiki”,"python","EG",
“ramayanam”,”valmiki”, "python","EG"]
False
author
price
4
['ramayanam', 'valmiki', "python","EG" , 450]
['welcome', 5, 6, 7]
['ramayanam', 'valmiki', "python", 4, 5,"EG",450]
['ramayanam', 'valmiki',4,5,450]
[450,5,4,'ramayanam', 'valmiki']
1
[]
OUTPUT:
TUPLE:
12134
(1, 2, 3)
123
(12134, 250000, 'books', 'totalprice')
('books', 'totalprice')
(12134, 250000, 'books', 'totalprice')
False
True
4
12134
250000
('books', 'totalprice')
('books', 'totalprice', 'books', 'totalprice', 'books', 'totalprice', 'books', 'totalprice')

RESULT:
Thus the Python program for implementing real time/technical library
applications using List and Tuple operations was implemented and successfully
verified.
EX.NO : 4 b Implementing real-time/technical applications using
DATE Lists, Tuple Operations(components of a car)

AIM:
To write a python program to add ,remove and pop the automobile
components using python List, Tuple operations.
ALGORITHM:

STEP 1: Start

STEP 2: Create the variable inside that variable assigned the list of elements
based on the car using List and Tuple operations
STEP 3: Using array index to print the items using list and Tuple operations

STEP 4: Display the result using output statement

STEP 5: Stop

PROGRAM:
LIST:
cars=[ "ac","airbags","accelerator","engine","battery","steering","engine",
"clutch","coolingsystem","ev"]
new_list = []
for i in cars:
if "a" in i:
new_list.append(i)
print(new_list)
c=[100,50,10,5,4]
c.sort()
print (c)
cars[0]="seatbelt"
print(cars[0])
cars[1]="bumper"
cars[2]="ignitionsystem"
cars[3]="wheels"
print(cars)
print (cars[:2])
print(cars[0:0])
component=["sunroof"]
print(cars+component)
print(cars*3)
print("brakes" in cars)
print(min(cars))
print(max(cars))
print(len(cars))
cars.append("fuel")
print(cars)
component.extend(["manual","automatic","mirror"])
print(component)
cars.insert(3,4)
cars.insert(4,5)
print(cars)
cars.remove("ev")
print(cars)
cars.pop(2)
print(cars)
cars.reverse()
print(cars)
print(cars.count("engine"))
component.clear()
mycars=component.copy()
print(mycars)

TUPLE:
tup1 = (12134, 250000,700)
tup2 = ('ac', 'mode')
print(tup1[0])

#trying to modify a tuple


tup1[0]='automatic' #error
print(tup1)#

mytup=1,2,3 #packing tuples


print(mytup)

mytuple = (1, 2, 3) #unpacking tuples


a, b, c = mytuple
print(a,b,c)

tup3 = tup1 + tup2


print(tup3)

print(tup3[2:])
print(tup3[0:4])
print('petrol' in tup1)
print(10 not in tup1)
print(len(tup3))
print(min(tup1))
print(max(tup1))

import copy
tup1=copy.copy(tup2)
print(tup1)

print(tup2*4)
OUTPUT:
LIST:
['ac', 'airbags', 'accelerator', 'battery']
[4, 5, 10, 50, 100]
seatbelt
['seatbelt', 'bumper', 'ignitionsystem', 'wheels', 'battery', 'steering',
'engine','clutch', 'coolingsystem', 'ev']
['seatbelt', 'bumper']
[]
['seatbelt', 'bumper', 'ignitionsystem', 'wheels', 'battery', 'steering', 'engine',
'clutch', 'coolingsystem', 'ev', 'sunroof']
['seatbelt', 'bumper', 'ignitionsystem', 'wheels', 'battery', 'steering', 'engine',
'clutch', 'coolingsystem', 'ev', 'seatbelt', 'bumper', 'ignitionsystem', 'wheels',
'battery', 'steering', 'engine', 'clutch', 'coolingsystem', 'ev', 'seatbelt', 'bumper',
'ignitionsystem', 'wheels', 'battery', 'steering', 'engine', 'clutch', 'coolingsystem',
'ev']
False
battery
wheels
10
['seatbelt', 'bumper', 'ignitionsystem', 'wheels', 'battery', 'steering', 'engine',
'clutch', 'coolingsystem', 'ev', 'fuel']
['sunroof', 'manual', 'automatic', 'mirror']
['seatbelt', 'bumper', 'ignitionsystem', 4, 5, 'wheels', 'battery', 'steering', 'engine',
'clutch', 'coolingsystem', 'ev', 'fuel']
['seatbelt', 'bumper', 'ignitionsystem', 4, 5, 'wheels', 'battery', 'steering', 'engine',
'clutch', 'coolingsystem', 'fuel']
['seatbelt', 'bumper', 4, 5, 'wheels', 'battery', 'steering', 'engine', 'clutch',
'coolingsystem', 'fuel']
['fuel', 'coolingsystem', 'clutch', 'engine', 'steering', 'battery', 'wheels', 5, 4,
'bumper', 'seatbelt']
1
[]
OUTPUT:
TUPLE:

12134
(1, 2, 3)
123
(12134, 250000, 700, 'ac', 'mode')
(700, 'ac', 'mode')
(12134, 250000, 700, 'ac')
False
True
5
700
250000
('ac', 'mode')
('ac', 'mode', 'ac', 'mode', 'ac', 'mode', 'ac', 'mode')

RESULT:
Thus the Python program to add ,remove and pop the automobile components using
python List,Tuple operations was implemented and verified successfully.
EX.NO : 4 c Implementing real-time/technical applications using
DATE Lists, Tuple operations (materials required for
construction of a building)

AIM:

To write a Python program to find the materials required for


construction of a building by using List and Tuple operations

ALGORITHM:

STEP 1: Start

STEP 2: Create the variable inside that variable assigned the list of elements based
on the materials required for construction of a building using List and Tuple
operations
STEP 3: Using array index to print the items using list and Tuple operations

STEP 4:Display the result using output statement

STEP 5: Stop

PROGRAM:
LIST:
materials= ["cementbags","carpenter","bricks", "sand","ceiling","Steelbars",
"Paint"]
new_list = []
for i in materials:
if "c" in i:
new_list.append(i)
print(new_list)
c=[100,50,10,5,4]
c.sort()
print (c)
materials[0]="tiles"
print(materials[0])
materials[1]="aggregates"
materials[2]="wiringsystem"
materials[3]="borewell"
print(materials)
print (materials[:2])
print(materials[0:0])
building=["s"]
print(materials+building)
print(materials*2)
print("walls" in materials)
print(min(materials))
print(max(materials))
print(len(materials))
materials.append("engineer")
print(materials)
building.extend(["machine","drilling","lift"])
print(building)
materials.insert(3,4)
materials.insert(4,5)
print(materials)
materials.remove("tiles")
print(materials)
materials.pop(2)
print(materials)
materials.reverse()
print(materials)
print(materials.count("engine"))
building.clear()
mymaterials=building.copy()
print(mymaterials)

TUPLE:

materials1 = ("cementbags", "bricks", "sand", "Steelbars", "Paint")


materials2 = ('water', 'equipments')
print(materials1[0])
building=1,2,3 #packing tuples
print(building)

building = (1, 2, 3) #unpacking tuples


a, b, c = building
print(a,b,c)

materials3 = materials1 + materials2


print(materials3)
print(materials3[2:])
print(materials3[0:4])
print('sand' in materials1)
print("tank" not in materials1)
print(len(materials3))
print(min(materials1))
print(max(materials1))

import copy
materials1=copy.copy(materials2)
print(materials1)

print(materials2*4)
OUTPUT:
LIST:
['cementbags', 'carpenter', 'bricks', 'ceiling']
[4, 5, 10, 50, 100]
tiles
['tiles', 'aggregates', 'wiringsystem', 'borewell', 'ceiling', 'Steelbars', 'Paint']
['tiles', 'aggregates']
[]
['tiles', 'aggregates', 'wiringsystem', 'borewell', 'ceiling', 'Steelbars', 'Paint', 's']
['tiles', 'aggregates', 'wiringsystem', 'borewell', 'ceiling', 'Steelbars', 'Paint', 'tiles',
'aggregates', 'wiringsystem', 'borewell', 'ceiling', 'Steelbars', 'Paint']
False
Paint
wiringsystem
7
['tiles', 'aggregates', 'wiringsystem', 'borewell', 'ceiling', 'Steelbars', 'Paint',
'engineer']
['s', 'machine', 'drilling', 'lift']
['tiles', 'aggregates', 'wiringsystem', 4, 5, 'borewell', 'ceiling', 'Steelbars', 'Paint',
'engineer']
['aggregates', 'wiringsystem', 4, 5, 'borewell', 'ceiling', 'Steelbars', 'Paint',
'engineer']
['aggregates', 'wiringsystem', 5, 'borewell', 'ceiling', 'Steelbars', 'Paint', 'engineer']
['engineer', 'Paint', 'Steelbars', 'ceiling', 'borewell', 5, 'wiringsystem', 'aggregates']
0
[]
OUTPUT:
TUPLE:
cementbags
(1, 2, 3)
123
('cementbags', 'bricks', 'sand', 'Steelbars', 'Paint', 'water', 'equipments')
('sand', 'Steelbars', 'Paint', 'water', 'equipments')
('cementbags', 'bricks', 'sand', 'Steelbars')
True
True
7
Paint
sand
('water', 'equipments')
('water', 'equipments', 'water', 'equipments', 'water', 'equipments', 'water',
'equipments')

RESULT:

Thus the Python program to find the materials required for


construction of a building by using List and Tuple operations was implemented
and verified successfully.
.
EX.NO : 5 Implementing real-time/technical applications using
DATE Sets(components of an automobile),
Dictionaries(Elements of civil structure)o p er a t io ns

AIM:

To write a python program to implementing real time /technical applications using


Sets and Dictionaries operations

ALGORITHM:

STEP 1: Start
STEP 2: Create the variable and stored the unordered list of elements based on
materials required for components of an automobile using set and dictionary
operations
STEP 3: Using for loop to list the number of elements and using array indexto
print the items using set and dictionary operations
STEP 4:Display the result using output statement
STEP 5: Stop

PROGRAM:
SETS:
automob1={"nano","tata","nexon","punch","nano","punch"}
print(automob1) #no duplicate items
automob1.add("xuv") #adding new item
print(automob1)
automob2={"kiya","creta",200}
automob2.update(automob1) #update automob2
print(automob2)
automob2.discard("creta") #remove an item
print(automob2)
market={100,200,500}
print(len(market)) #length
print(automob2.union(market)) #union
print(automob2.intersection(market)) #intersection
print(automob2.clear())
import copy
automob2=copy.copy(automob1) #copy automob1 to automob2
print(automob2)
set1 = {1, 2, 3, 4, 5}
set2 = {2, 4}
print(set2.issubset(set1))

print(set2.issuperset(set1))
set1 = {1, 2, 3, 4, 5}
set2 = {6, 7, 8}
print(set1.isdisjoint(set2))
print(automob1.pop()) #pop

OUTPUT:
SETS:
{'tata', 'nano', 'nexon', 'punch'}
{'nexon', 'nano', 'punch', 'xuv', 'tata'}
{'creta', 'nexon', 'kiya', 200, 'nano', 'punch', 'xuv', 'tata'}
{'nexon', 'kiya', 200, 'nano', 'punch', 'xuv', 'tata'}
3
{'nexon', 100, 'kiya', 200, 'punch', 'nano', 'xuv', 500, 'tata'}
{200}
None
{'xuv', 'nexon', 'punch', 'tata', 'nano'}
True
False
True
nexon

PROGRAM:

DICTIONARY (Elements of civil structure)


Dict = {}
print(Dict)

# Adding elements one at a time


Dict[0] = 'BRICKS'
Dict[2] = 'CEMENT'
Dict[3] = 'BLUEPRINT'
print(Dict)

# Adding set of values to a single Key


Dict['Value_set'] = 2, 3, 4
print(Dict)

# Updating existing Key's Value


Dict[2] = 'STEEL'
print("\nUpdated key value: ")
print(Dict)

# Adding Nested Key value to Dictionary


Dict[5] = {'Nested': {'1': 'LIME', '2': 'SAND'}}
print("\nAdding a Nested Key: ")
print(Dict)

construct={"bricks":"sand","cement":"concrete"}
print(construct)
print(construct["bricks"])
print(construct["cement"])
construct["chips"]="stone"
print(construct)
del construct['bricks']
print(construct)
construct["cement"]="birla"
print(construct)
# print dictionary keys one by one
for i in construct:
print(construct)
print(len(construct))
print(construct.keys())
print(construct.values())
print(construct.popitem())
print(construct.get("bricks"))
print(construct.get("cement"))
OUTPUT
DICTIONARY:
{}

{0: 'BRICKS', 2: 'CEMENT', 3: 'BLUEPRINT'}

{0: 'BRICKS', 2: 'CEMENT', 3: 'BLUEPRINT', 'Value_set': (2, 3, 4)}

Updated key value:


{0: 'BRICKS', 2: 'STEEL', 3: 'BLUEPRINT', 'Value_set': (2, 3, 4)}

Adding a Nested Key:


{0: 'BRICKS', 2: 'STEEL', 3: 'BLUEPRINT', 'Value_set': (2, 3, 4), 5: {'Nested': {'1':
'LIME', '2': 'SAND'}}}

{'bricks': 'sand', 'cement': 'concrete'}


sand
concrete
{'bricks': 'sand', 'cement': 'concrete', 'chips': 'stone'}
{'cement': 'concrete', 'chips': 'stone'}
{'cement': 'birla', 'chips': 'stone'}
{'cement': 'birla', 'chips': 'stone'}
{'cement': 'birla', 'chips': 'stone'}
2
dict_keys(['cement', 'chips'])
dict_values(['birla', 'stone'])
('chips', 'stone')
None
birla

RESULT:

Thus the python program to implementing real time /technical applications by


using Sets and Dictionaries operations was implemented and verified
successfully.

You might also like