0% found this document useful (0 votes)
6 views3 pages

Python List Management Menu Code

The document provides a Python code for a list menu that allows users to perform various operations on a list, including adding, removing, popping, deleting elements, printing the list, and exiting the program. It utilizes a while loop to continuously prompt the user for actions until they choose to exit. The code includes input validation to ensure that the user interacts with the list correctly.
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)
6 views3 pages

Python List Management Menu Code

The document provides a Python code for a list menu that allows users to perform various operations on a list, including adding, removing, popping, deleting elements, printing the list, and exiting the program. It utilizes a while loop to continuously prompt the user for actions until they choose to exit. The code includes input validation to ensure that the user interacts with the list correctly.
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

List Menu Code in Python

l=[]
while True:
print('List Menu')
x=int(input("""What do you want to do
Enter 1 to add element to list
Enter 2 to remove element from list
Enter 3 to pop
Enter 4 to delete element
Enter 5 to print list
Enter 6 to exit """))
if x==1:
while True:
y=int(input('Enter Number '))
[Link](y)
co=input('Do you want to continue adding
elements Yes or No')
if co in 'NOnoNonO':
break
elif x==2:
while True:
y=int(input('Enter Number '))
if y in l:
[Link](y)
else:
print('Please enter elements which are there
in the list')
co=input('Do you want to continue removing
elements Yes or No')
if co in 'NOnoNonO':
break
elif x==3:
if len(l)!=0:
while True:
[Link]()
co=input('Do you want to continue popping
elements Yes or No')
if co in 'NOnoNonO':
break
if len(l)==0:
print('list is now Empty')
break
else:
print('List is empty')
elif x==4:
while True:
s=int(input('Enter the serial number of the
element which you want to delete : '))
s-=1
if s<0 or s>len(l):
print('Please Enter a valid serial number')
else:
del l[s]
co=input('Do you want to continue deleting
elements Yes or No')
if co in 'NOnoNonO':
break
elif x==5:
print(l)
elif x==6:
exit()
else:
print('Please enter a valid choice')
con=input('Do you want to continue to main menu Yes
or No')
if con in 'NOnoNonO':
break

You might also like