Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- L = []
- n = int(input("Enter the number of elements in the list: "))
- for k in range(n):
- a = input("Enter the element to be added in the list: ")
- L.append(a)
- print("List created")
- print("The list is: ",L)
- print("1. Append an element")
- print("2. Insert an element")
- print("3. Modify an existing element by accepting it's position")
- print("4. Delete an existing element from its position")
- print("5. Delete an existing element with a given value")
- print("6. Sort the list in ascending order")
- print("7. Sort the list in descending order")
- print("8. Display the list")
- print("Do you want to continue?? (Y/n)")
- print("Program Starting")
- s_l = input("\n\nEnter your selection: ")
- if s_l == '1':
- print("You selected to append an element")
- b = input("Enter the element to be appended into the list: ")
- L.append(b)
- print("\n List updated")
- print("The new list is: ",L)
- elif s_l == '2':
- print("You selected to insert an element")
- d = int(input("Enter the position of the element in the list: "))
- c = input("Enter the element to be inserted into the list: ")
- L.insert(d,c)
- print("\n List updated")
- print("The new list is: ",L)
- elif s_l == '3':
- print("You selected to modify an existing element by accepting it's position")
- e = int(input("Enter the position of the element: "))
- f = input("Enter the element to be added into the list by replacing the previous one: ")
- L[e] = f
- print("List updated")
- print("The new list is: ",L)
- elif s_l == '4':
- print("You selected to delete an existing element from it's position")
- g = int(input("Enter the position of the element: "))
- L.pop(g)
- print("List updated")
- print("The new list is: ",L)
- elif s_l == '5':
- print("You selected to delete an existing element with a given value")
- h = input("Enter the value of the element to be removed: ")
- L.remove(h)
- print("List updated")
- print("The new list is: ",L)
- elif s_l == '6':
- print("You selected to sort the list in ascending order")
- i = L.sort()
- print("List updated")
- print("The new list is: ",i)
- elif s_l == '7':
- print("You selected to sort the list in descending order")
- j = L.sort(reverse=True)
- print("List updated")
- print("The new list is: ",j)
- elif s_l == '8':
- print("You selected to display the list")
- print("The list is: ",L)
- elif s_l == 'Y':
- print("You selected to continue the program")
- print("Continuing")
- elif s_l == 'n':
- print("You selected to quit")
- print("Thank you for using me")
- print("Program ending")
- quit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement