0
0
DSA Pythonprogramming~10 mins

Why Arrays Exist and What Problem They Solve in DSA Python - Test Your Knowledge

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

Complete the code to create an array with 5 elements initialized to zero.

DSA Python
arr = [[1]] * 5
print(arr)
Drag options to blanks, or click blank then click option'
A0
BNone
C1
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using None instead of 0 will create an array of None values.
Using 1 will create an array of ones, not zeros.
2fill in blank
medium

Complete the code to access the third element of the array.

DSA Python
arr = [10, 20, 30, 40, 50]
print(arr[[1]])
Drag options to blanks, or click blank then click option'
A3
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 will access the fourth element, not the third.
Using index 1 will access the second element.
3fill in blank
hard

Fix the error in the code to correctly update the second element of the array to 99.

DSA Python
arr = [5, 10, 15]
arr[[1]] = 99
print(arr)
Drag options to blanks, or click blank then click option'
A3
B2
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 2 updates the third element, not the second.
Using index 3 causes an index error because the array has only 3 elements.
4fill in blank
hard

Fill both blanks to create an array of squares of numbers from 1 to 5.

DSA Python
squares = [x[1]2 for x in range(1, [2])]
print(squares)
Drag options to blanks, or click blank then click option'
A**
B6
C*
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' multiplies but does not square the number in this context.
Using 5 as range end excludes the number 5.
5fill in blank
hard

Fill both blanks to create a dictionary of numbers and their cubes for numbers greater than 2.

DSA Python
cubes = {x: x{BLANK_2}}3 for x in range(1, 6) if x {{BLANK_2}} 2
print(cubes)
Drag options to blanks, or click blank then click option'
Ax
B**
C>
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Using '(' instead of '{' will cause a syntax error.
Using '*' instead of '**' will multiply but not cube.
Using '<' instead of '>' will filter wrong numbers.