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: [10, 20, 30, 40, 50].
  2. Append the integer 60 to the list.
  3. Insert the integer 25 at index 2.
  4. Sort the list in ascending order.
  5. Search for the integer 30 in the list and print its index.
  6. Print the final list.

Python List Manipulation

2 Likes

Answer

numbers = [10, 20, 30, 40, 50]
numbers.append(60)
numbers.insert(2, 25)
numbers.sort()
index_30 = numbers.index(30)
print("Index of 30:", index_30)
print("Final list:", numbers)

Output

Index of 30: 3
Final list: [10, 20, 25, 30, 40, 50, 60]

Answered By

3 Likes


Related Questions