Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the length counter to zero.
DSA Python
def get_length(head): length = [1] current = head while current: length += 1 current = current.next return length
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting length at 1 instead of 0
Setting length to None
Assigning length to head
✗ Incorrect
We start counting from zero because the list might be empty.
2fill in blank
mediumComplete the code to move to the next node in the linked list.
DSA Python
def get_length(head): length = 0 current = head while current: length += 1 current = [1] return length
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using head.next instead of current.next
Assigning current to itself causing infinite loop
Using length.next which is invalid
✗ Incorrect
To move forward, we assign current to the next node.
3fill in blank
hardFix the error in the loop condition to correctly check if the current node exists.
DSA Python
def get_length(head): length = 0 current = head while [1]: length += 1 current = current.next return length
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'current == None' which is less preferred
Using 'head' which does not change in the loop
Using 'length' which is an integer
✗ Incorrect
The loop should continue while current is not None.
4fill in blank
hardFill both blanks to create a dictionary with word lengths for words longer than 3 characters.
DSA Python
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {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 '<' instead of '>'
Using 'word' instead of 'len(word)'
Not filtering words by length
✗ Incorrect
We want the length of each word and only include words longer than 3 characters.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values greater than zero.
DSA Python
data = {'a': 1, 'b': 0, 'c': 3}
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 'k' instead of 'k.upper()' for keys
Using '<' instead of '>' for filtering
Including values equal to zero
✗ Incorrect
Keys are converted to uppercase, values are included if greater than zero.