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

List Program

a

Uploaded by

mehra.01.krishna
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)
8 views

List Program

a

Uploaded by

mehra.01.krishna
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/ 2

val = [17, 23, 18, 19]

print('the list is:', val)

while True:

print('main menu:')

print('1. insert')

print('2. delete')

print('3. exit')

ch = int(input("enter the choice 1/2/3:"))

if ch == 1:

item = int(input("enter the item:"))

pos = int(input("insert at which position?"))

index = pos - 1

val.insert(index, item)

print("success! list now is:", val)

elif ch == 2:

print("deletion menu:")

print('1. delete using value')

print('2. delete using index')

print('3. delete using sublist')

dch = int(input("enter the choice (1 or 2 or 3):"))

if dch == 1:

item = int(input("enter item to be deleted:"))

val.remove(item)

print('list is now:', val)


elif dch == 2:

index = int(input("enter index of item to be deleted:"))

val.pop(index)

print('list is now:', val)

elif dch == 3:

l = int(input("enter lower limit of list slice to be deleted:"))

h = int(input("enter upper limit of list slice to be deleted:"))

del val[l:h]

print('list is now:', val)

else:

print('valid choices are 1/2/3 only')

elif ch == 3:

break

else:

print('valid choices are 1/2/3 only')

You might also like