0
0
DSA Pythonprogramming~10 mins

Array Insertion at Middle Index in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to insert the value 99 at the middle index of the list.

DSA Python
arr = [1, 2, 3, 4, 5]
mid = len(arr) // 2
arr.[1](mid, 99)
print(arr)
Drag options to blanks, or click blank then click option'
Aappend
Binsert
Cextend
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using append adds the element at the end, not the middle.
Using remove deletes elements instead of adding.
2fill in blank
medium

Complete the code to find the middle index of the list correctly.

DSA Python
arr = [10, 20, 30, 40, 50, 60]
mid = [1]
print(mid)
Drag options to blanks, or click blank then click option'
Alen(arr) // 2
Blen(arr) / 2
Clen(arr) % 2
Darr[len(arr)]
Attempts:
3 left
💡 Hint
Common Mistakes
Using regular division returns a float, which is invalid as a list index.
Using modulo operator does not give the middle index.
3fill in blank
hard

Fix the error in the code to insert 77 at the middle index of the list.

DSA Python
numbers = [5, 10, 15, 20]
middle = len(numbers) // 2
numbers.[1](middle, 77)
print(numbers)
Drag options to blanks, or click blank then click option'
Aappend
Bextend
Cinsert
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using append adds at the end, not at the middle index.
Using add or extend are invalid for this operation.
4fill in blank
hard

Fill both blanks to create a list of squares for numbers less than 5 and insert 100 at the middle index.

DSA Python
nums = [1, 2, 3, 4, 5, 6]
squares = [x[1]2 for x in nums if x [2] 5]
mid = len(squares) // 2
squares.insert(mid, 100)
print(squares)
Drag options to blanks, or click blank then click option'
A**
B>
C<
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '**' does addition, not squaring.
Using '>' instead of '<' filters wrong numbers.
5fill in blank
hard

Fill all three blanks to create a dictionary of numbers and their squares for numbers greater than 2, then insert 50 at the middle index of the list.

DSA Python
nums = [1, 2, 3, 4, 5]
squares_dict = {{ [1]: [2] for [1] in nums if [1] [3] 2 }}
nums.insert(len(nums)//2, 50)
print(nums)
print(squares_dict)
Drag options to blanks, or click blank then click option'
Ax
Bx**2
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' filters wrong numbers.
Using the wrong variable name causes errors.