[go: up one dir, main page]

0% found this document useful (0 votes)
7 views6 pages

Ex 4

The document contains a series of programming exercises focusing on implementing real-time applications using lists and tuples. It includes examples of managing a library system, selecting car models, calculating construction materials, and performing various list operations. Each section provides input and output examples demonstrating the functionality of the code.

Uploaded by

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

Ex 4

The document contains a series of programming exercises focusing on implementing real-time applications using lists and tuples. It includes examples of managing a library system, selecting car models, calculating construction materials, and performing various list operations. Each section provides input and output examples demonstrating the functionality of the code.

Uploaded by

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

HARIKRISHNAN K

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

1.Display the Books


2.Request a Books
3.Return a Book
4.Exit
Enter your choice:1
The Available Books are ['C++', 'Java', 'Python']
1.Display the Books
2.Request a Books
3.Return a Book
4.Exit
Enter your choice:3
Enter the book you want to return:MySql
MySql Successfully returned
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:4

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

print("brick not available")


print("material required for your construction is,material")
Output :
What is the construction area : 400
('OPS', 'WPC', 'LHC')
Enter the cement to be used : LHC
Enter sand to be used : FS
('CS', 'FS', 'CS')
('SDB', 'BCB', 'CB')
Enter the bricks to be used : CB
Material required for your construction is
LHC 160.0bags
FS 320.0ton
CB 3200.0pcs
SIMPLE PROGRAM USING LIST
A.Insert an element at the position 5:
Input :
List= [1,2,3,4,5,8]
List.insert (5,6)
Print(list)
Output :
[1,2,3,4,5,6,8]
B. Insert an element
Input :
list=[1,2,3,4,5,6,7,8]
list.append(9)
print(list)
Output :
[1,2,3,4,5,6,7,8,9]
C. Display the elements of a list :
Input :
list=[1,2,3,4,5,6,7,8]
print("The element in list are:")
print(list)
Output :
The elements in the list are :[1,2,3,4,5,6,7,8]
D. Update the element at the 3rd position to its negative value :
Input :
list=[1,2,3,4,5,6,7,8]
list[5]=-list[5]
print(list)
Output :
[1,2,3,-4,5,6,7,8]
E. Display the elements :
Input :
list=[1,2,3,4,5,6]
for x in list:
print(x)
Output :
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]

You might also like