-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment.py
More file actions
32 lines (26 loc) · 925 Bytes
/
Assignment.py
File metadata and controls
32 lines (26 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 1. Create an empty list called my_list.
my_list = []
# 2. Append the following elements to my_list: 10, 20, 30, 40.
my_list.append(10)
my_list.append(20)
my_list.append(30)
my_list.append(40)
print(f"After appending elements: {my_list}")
# 3. Insert the value 15 at the second position in the list.
my_list.insert(1, 15)
print(f"After inserting 15: {my_list}")
# 4. Extend my_list with another list: [50, 60, 70].
my_list.extend([50, 60, 70])
print(f"After extending with [50, 60, 70]: {my_list}")
# 5. Remove the last element from my_list.
my_list.pop()
print(f"After removing the last element: {my_list}")
# 6. Sort my_list in ascending order.
my_list.sort()
print(f"After sorting: {my_list}")
# 7. Find and print the index of the value 30 in my_list.
try:
index_of_30 = my_list.index(30)
print(f"The index of the value 30 is: {index_of_30}")
except ValueError:
print("The value 30 is not in the list.")