Professional Documents
Culture Documents
Python Programs
Python Programs
Python Programs
List Programs
1. Enter a list and input 1 to add an element, 2 to delete an
element and 3 to exit the program (it should happen
endlessly until 3 is inputed):
l=[]
a=0
f=0
n=int(input("Enter the number of elements: "))
for i in range(0,n,1):
a=int(input("enter number: "))
l.append(a)
while(True):
c=int(input("Enter 1 to insert an element, 2 to delete an
element, 3 to exit the program: "))
if(c==1):
x=input("enter the element to enter into a list: ")
l.append(x)
print("new list: ")
f+=1
for i in range(0,n+f,1):
print(l[i])
elif(c==2):
x=int(input("Enter the index number of the element to
remove from the list: "))
l.pop(x)
f+=1
print("New list: ")
for i in range(0,n-f,1):
print(l[i])
elif(c==3):
break