KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Write a Python program that performs the following operations on a list of integers:

  1. Create a list of integers: [5, 15, 25, 35, 45].
  2. Append the integer 55 to the list.
  3. Insert the integer 20 at index 1.
  4. Remove the integer 35 from the list.
  5. Find the index of the integer 25 and print it.
  6. Print the final list.

Python List Manipulation

3 Likes

Answer

numbers = [5, 15, 25, 35, 45]

numbers.append(55)

numbers.insert(1, 20)

numbers.remove(35)

index_25 = numbers.index(25)
print("Index of 25:", index_25)

print("Final list:", numbers)

Output

Index of 25: 3
Final list: [5, 20, 15, 25, 45, 55]

Answered By

1 Like


Related Questions