Advertisement
ALENTL

main.py

Jan 18th, 2022
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. L = []
  2.  
  3. n = int(input("Enter the number of elements in the list: "))
  4.  
  5. for k in range(n):
  6.     a = input("Enter the element to be added in the list: ")
  7.     L.append(a)
  8.  
  9. print("List created")
  10. print("The list is: ",L)
  11.  
  12. print("1. Append an element")
  13. print("2. Insert an element")
  14. print("3. Modify an existing element by accepting it's position")
  15. print("4. Delete an existing element from its position")
  16. print("5. Delete an existing element with a given value")
  17. print("6. Sort the list in ascending order")
  18. print("7. Sort the list in descending order")
  19. print("8. Display the list")
  20.  
  21. print("Do you want to continue?? (Y/n)")
  22.  
  23. print("Program Starting")
  24.  
  25. s_l = input("\n\nEnter your selection: ")
  26.  
  27. if s_l == '1':
  28.     print("You selected to append an element")
  29.     b = input("Enter the element to be appended into the list: ")
  30.     L.append(b)
  31.     print("\n List updated")
  32.     print("The new list is: ",L)
  33.  
  34. elif s_l == '2':
  35.     print("You selected to insert an element")
  36.     d = int(input("Enter the position of the element in the list: "))
  37.     c = input("Enter the element to be inserted into the list: ")
  38.     L.insert(d,c)
  39.     print("\n List updated")    
  40.     print("The new list is: ",L)
  41.  
  42. elif s_l == '3':
  43.     print("You selected to modify an existing element by accepting it's position")
  44.     e = int(input("Enter the position of the element: "))
  45.     f = input("Enter the element to be added into the list by replacing the previous one: ")
  46.     L[e] = f
  47.     print("List updated")
  48.     print("The new list is: ",L)
  49.  
  50. elif s_l == '4':
  51.     print("You selected to delete an existing element from it's position")
  52.     g = int(input("Enter the position of the element: "))
  53.     L.pop(g)
  54.     print("List updated")
  55.     print("The new list is: ",L)
  56.  
  57. elif s_l == '5':
  58.     print("You selected to delete an existing element with a given value")
  59.     h = input("Enter the value of the element to be removed: ")
  60.     L.remove(h)
  61.     print("List updated")
  62.     print("The new list is: ",L)
  63.  
  64. elif s_l == '6':
  65.     print("You selected to sort the list in ascending order")
  66.     i = L.sort()
  67.     print("List updated")
  68.     print("The new list is: ",i)
  69.  
  70. elif s_l == '7':
  71.     print("You selected to sort the list in descending order")
  72.     j = L.sort(reverse=True)
  73.     print("List updated")
  74.     print("The new list is: ",j)
  75.  
  76. elif s_l == '8':
  77.     print("You selected to display the list")
  78.     print("The list is: ",L)
  79.  
  80. elif s_l == 'Y':
  81.     print("You selected to continue the program")
  82.     print("Continuing")
  83.  
  84. elif s_l == 'n':
  85.     print("You selected to quit")
  86.     print("Thank you for using me")
  87.     print("Program ending")
  88.     quit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement