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

Python Programming Lab 3

Uploaded by

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

Python Programming Lab 3

Uploaded by

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

3(a):Implementing real-time/technical applications

using Lists, Tuples. (Items present in a


Library/Retail Store –operations of list & tuples)

list=int(input("Enter the Number of Books:"))


l=[]
for i in range(list):
Books=input("Enter the Book Name:")
l.append(Books)
print("Original List:")
print(l)
insert1=int(input("Enter the Position to insert the book:"))
a=input("Enter the Book:")
l.insert(insert1,a)
print("After inserting the Book:")
print(l)
print("After removing the first book:")
l.remove(l[0])
print(l)
print("Length of Final List:")
print(len(l))
print("Convert List to Tuple")
l=tuple(l)
print(l)
Output

Enter the Number of Books:2


Enter the Book Name:Python Programming
Enter the Book Name:Engineerong Graphics
Original List:
['Python Programming', 'Engineerong Graphics']
Enter the Position to insert the book:0
Enter the Book:Circuits
After inserting the Book:
['Circuits', 'Python Programming', 'Engineerong Graphics']
After removing the first book:
['Python Programming', 'Engineerong Graphics']
Length of Final List:
2
Convert List to Tuple
('Python Programming', 'Engineerong Graphics')
3(b)Items present in Retail Store
tup=('Rice','Flour','Milk','Bread','Biscuit','Rice')
print("original Tuple:")
print(tup)
print("Enter the number of Items:",len(tup))
a=tup.count("Rice")
print("Rice appears",a,"times" )
b=tup.index("Flour")
print("index of Flour is",b)
print("Tuple to List")
l=list(tup)
print(l)

Output

original Tuple:
('Rice', 'Flour', 'Milk', 'Bread', 'Biscuit', 'Rice')
Enter the number of Items: 6
Rice appears 2 times
index of Flour is 1
Tuple to List
['Rice', 'Flour', 'Milk', 'Bread', 'Biscuit', 'Rice']

You might also like