Ex 4
Ex 4
22IT021
EXPERIMENT-4
IMPLEMENTING REAL-TIME/TECHNICAL APPLICATIONS USING LISTS ,TUPLES
1.Items present in the library
Program:
b=[]
nl=int(input("Enter total no of books"))
for i in range(nl):
a=input("Enter book names")
b.append(a)
print("The academic books in the library are",b)
for i in range(2):
print("l.Display no of books\n2.request a book\n3.return a book")
c=int(input("Enter your choice"))
if c==1:
print("The total no of books in the library are",len(b))
print("The books in the library are",sorted(b))
elif c==2:
bl=input("Enter the name of the books")
if bl in b:
b.remove(bl)
print("Successfully issued")
else:
print("Book not available")
elif c==3:
bl=input("Enter the name of the book")
b.append(bl)
print("Sucessfully returned")
else:
break
Output :
Enter the No of Books:4
Enter the Book Name:Python
Enter the Book Name:C++
Enter the Book Name:Java
Enter the Book Name:MySql
1.Display the Books
2.Request a Books
3.Return a Book
4.Exit
Enter your choice:1
The Available Books are ['C++', 'Java', 'MySql', 'Python']
1.Display the Books
2.Request a Books
3.Return a Book
4.Exit
Enter your choice:2
Enter the Book you want:MySql
MySql is Successfully Removed
HARIKRISHNAN K
22IT021
2. Components of a car
Input :
M=("Kia seltos","Tata punch","Renault","Maruti")
print("Car Mode\n",M)
model=input("Enter the model you want")
if model in M:
print("Model is available")
p=(9,4,5,6,7)
Color=("Grey","Blue","Solid fire red","Silver")
Lowest_price=min(p)
Highest_price=max(p)
print("Strting price in lakhs",Lowest_price,"Highest price in lakhs",Highest_price)
type1=input("Enter the fuel type")
air_bags=input("Need air bags in your car yes/no")
if type=="petrol" and air_bags=="no":
print("You can purchase Tata punch Renault or maruti")
else:
print("You can purchase Kia seltos")
c=input("Enter the color")
if c in Color:
print("Yeah!available you can purchase")
else:
HARIKRISHNAN K
22IT021
print("Out of Stock")
else:
print("The model is not available")
Output :
Car Mode
('Kia seltos', 'Tata punch', 'Renault', 'Maruti')
Enter the model you wantKia seltos
Model is available
Starting price in lakhs 4 Highest price in lakhs 9
Enter the fuel typepetrol
Need air bags in your car yes/nono
You can purchase Kia seltos
Enter the color Blue
Yeah!available you can purchase
3.Materials required for construction of a building
Input :
cement_1=40/100
sand_1=80/100
brick_1=800/100
mybuild=[]
material=[]
area=int(input("what is the construction area"))
cement=("OPS","WPC","LHC")
sand=("CS","FS","CS")
bricks=("SDB","BCB","CB")
print(cement)
cem=input("enter the cement to be used")
if cem in cement:
material.append(str(area*cement_1)+"bags")
mybuild.append(cem)
else:
print("cement not available")
print(sand)
s=input("enter sand to be used")
if s in sand :
material.append(str(area*sand_1)+"ton")
mybuild.append(s)
else:
print("cement not available")
b=input("enter the brick to be used")
print(bricks)
b=input("enter the bricks to be used")
if b in bricks:
material.append(str(area*brick_1)+"pcs")
mybuild.append(b)
else:
HARIKRISHNAN K
22IT021
1
2
3
4
5
6
F. Calculate the square of each element of list :
Input :
list=[1,2,3,4,5,6,7,8]
for i in list:
print(i**2)
Output :
1
4
9
16
25
36
49
64
G. Find the largest and smallest number of the list :
Input :
list=[1,2,3,4,5,6,7,8]
largest=max(list)
smallest=min(list)
print("largest number in the list",largest)
print("smallest number in the list",smallest)
SS
Largest number in the list : 8
Smallest number in the list : 1
H. Split the list into two sub list based on the number of elements :
Input :
list=[1,2,3,4,5,6,7,8]
list1=list[:5]
list2=list[5:]
print("the first sublist is:",list1)
print("the second sublist is:",list2)
Output :
The first sublist :[1,2,3,4,5]
The second sublist is :[6,7,8]
I.Create a list in which one list contains even number and the other list contains odd numbers :
Input :
l=[1,2,3,4,5,6,7,8]
li=[]
lis=[]
for i in l:
if i%2==0:
li.append(i)
else:
lis.append(i)
HARIKRISHNAN K
22IT021
print(li)
print(lis)
Output :
[2,4,6,8]
[1,3,5,7]
J.Dispaly the elements in ascending order :
Input :
list=[1,2,3,4,5,6,8,10,9]
list.sort()
print("The list elements in ascending order:",list)
Output :
[1,2,3,4,5,6,7,8]
K.Interchange the position of 1st and last element :
Input :
list=[1,2,3,4,5,6,7,8]
list[0],list[-1]=list[-1],list[0]
print(list)
Output :
[8,2,3,4,5,6,7,1]
L.Delete the element at the position :
Input :
List= [1,2,3,4,5,6,7,8]
Position=4
Del list [position]
Print(list)
Output :
[1,2,3,4,6,7,8]
M.Delete the last element :
Input :
list=[1,2,3,4,5,6,7,8]
list.pop()
print(list)
Output :
[1,2,3,4,5,6,7]
N.Delete the entire list :
Input :
list=[1,2,3,4,5,6,7,8]
list.clear()
print(list)
Output :
[]
O.Reverse the list elements :
Input :
list=[1,2,3,4,5,6,7,8]
list.reverse()
print(list)
Output :
[8,7,6,5,4,3,2,1]