Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print all elements of the list forward.
DSA Python
for i in range(len(lst)): print(lst[[1]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the list itself as an index like lst[lst[i]]
Using a fixed index like 0 instead of the loop variable
✗ Incorrect
We use the loop variable 'i' to access each element in the list by index.
2fill in blank
mediumComplete the code to print all elements of the list backward.
DSA Python
for i in range(len(lst)-1, [1], -1): print(lst[i])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as stop index which excludes index 0
Using len(lst) which is out of range
✗ Incorrect
To go backward through the list, we start from the last index and go down to -1 (exclusive) to include index 0.
3fill in blank
hardFix the error in the code to traverse the list forward and print elements.
DSA Python
i = 0 while i < [1]: print(lst[i]) i += 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing 'i' with the list itself instead of its length
Using a fixed number instead of the list length
✗ Incorrect
The loop should run while 'i' is less than the length of the list to cover all elements.
4fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 characters.
DSA Python
{word: [1] for word in words if len(word) [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length
Using '<' instead of '>' in the condition
✗ Incorrect
We want the length of each word as the value and only include words longer than 3 characters.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values for positive values only.
DSA Python
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys instead of uppercase
Using '<' instead of '>' in the condition
Using keys as values
✗ Incorrect
Keys are uppercase versions of k, values are v, and we include only positive values (v > 0).