Create list and perform append, pop, and slice operation.
SOLUTION.
# Creating an empty list
my_list = []
# Taking dynamic input from the user
n = int(input("Enter the number of elements you want in the list: "))
# Appending elements to the list
for i in range(n):
element = input(f"Enter element {i+1}: ")
my_list.append(element)
# Displaying the list after appending
print("List after appending elements:", my_list)
# Performing pop operation
if my_list:
popped_element = my_list.pop() # Removes the last element
print("Popped element:", popped_element)
print("List after pop operation:", my_list)
# Performing slice operation
start = int(input("Enter the start index for slicing: "))
end = int(input("Enter the end index for slicing: "))
sliced_list = my_list[start:end] # Slicing the list
print("Sliced list:", sliced_list)