#Tuples
"""
Implementing real-time/technical applications using Tuples - Materials required for construction of a building - operations of tuples
"""
"""
Materials required for construction of a building
Cement
Bricks
Blocks
Wooden Products
Hardware and Fixtures
Natural Stones
Doors
Windows
Modular Kitchen
Sand
Aggregates
Electrical materials
Tiles
"""
"""
Operations of tuples - Create, access element, splice, len, concat, repetition, membership, iteration
"""
# Creating a tuple
BuildingMaterials = ('Cement', 'Bricks', 'Blocks', 'Wooden Products', 'Hardware and Fixtures', 'Natural Stones', 'Doors', 'Windows', 'Modular Kitchen', 'Sand','Aggregates', 'Tiles')
ElectricalMaterials = ('Conduit Pipes and Fittings', 'Wires and Cables', 'Modular switches and sockets', 'Electric Panels', 'Switch Gear')
print("Created tuple : ")
print("Building Materials : ",BuildingMaterials)
print("Electrical Materials : ",ElectricalMaterials)
# Accessing elements by index
print("First element in tuple : ",BuildingMaterials[0])
print("Last element in tuple : ",BuildingMaterials[-1])
# Splicing
print("First 5 elements in tuple : ",BuildingMaterials[0:5])
# length of tuple
print("Length of tuple : ",len(BuildingMaterials))
# Concat, repetition
print("Concatenation operation")
AllMaterials = BuildingMaterials+ElectricalMaterials
print("All materials")
print(AllMaterials)
print("Repetition operation")
print(AllMaterials*2)
# Membership operator
SearchMaterial = input("Enter material to search : ")
if SearchMaterial in AllMaterials:
print("Material present in tuple.")
else:
print("Material not present in tuple.")
# Iteration operation
print("Iteration operation")
print("Materials required for construction of a building: ")
for mat in AllMaterials:
print(mat)
"""
Sample output
>python Tuple1.py
Created tuple :
Building Materials : ('Cement', 'Bricks', 'Blocks', 'Wooden Products', 'Hardware and Fixtures', 'Natural Stones', 'Doors', 'Windows', 'Modular Kitchen', 'Sand', 'Aggregates', 'Tiles')
Electrical Materials : ('Conduit Pipes and Fittings', 'Wires and Cables', 'Modular switches and sockets', 'Electric Panels', 'Switch Gear')
First element in tuple : Cement
Last element in tuple : Tiles
First 5 elements in tuple : ('Cement', 'Bricks', 'Blocks', 'Wooden Products', 'Hardware and Fixtures')
Length of tuple : 12
Concatenation operation
All materials
('Cement', 'Bricks', 'Blocks', 'Wooden Products', 'Hardware and Fixtures', 'Natural Stones', 'Doors', 'Windows', 'Modular Kitchen', 'Sand', 'Aggregates', 'Tiles', 'Conduit Pipes and Fittings', 'Wires and Cables', 'Modular switches and sockets', 'Electric Panels', 'Switch Gear')
Repetition operation
('Cement', 'Bricks', 'Blocks', 'Wooden Products', 'Hardware and Fixtures', 'Natural Stones', 'Doors', 'Windows', 'Modular Kitchen', 'Sand', 'Aggregates', 'Tiles', 'Conduit Pipes and Fittings', 'Wires and Cables', 'Modular switches and sockets', 'Electric Panels', 'Switch Gear', 'Cement', 'Bricks', 'Blocks', 'Wooden Products', 'Hardware and Fixtures', 'Natural Stones', 'Doors', 'Windows', 'Modular Kitchen', 'Sand', 'Aggregates', 'Tiles', 'Conduit Pipes and Fittings', 'Wires and Cables', 'Modular switches and sockets', 'Electric Panels', 'Switch Gear')
Enter material to search : Sand
Material present in tuple.
Iteration operation
Materials required for construction of a building:
Cement
Bricks
Blocks
Wooden Products
Hardware and Fixtures
Natural Stones
Doors
Windows
Modular Kitchen
Sand
Aggregates
Tiles
Conduit Pipes and Fittings
Wires and Cables
Modular switches and sockets
Electric Panels
Switch Gear
"""
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu