Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to calculate the sum of numbers in the list.
Python
numbers = [1, 2, 3, 4, 5] total = [1](numbers) print(total)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using len() instead of sum() which returns the count, not the total.
Using max() or min() which return the largest or smallest number, not the sum.
โ Incorrect
The sum() function adds all numbers in the list and returns the total.
2fill in blank
mediumComplete the code to calculate the sum of numbers from 1 to 5 using range.
Python
total = [1](range(1, 6)) print(total)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using len() which returns the count of numbers, not their sum.
Using max() or min() which return single values, not the total.
โ Incorrect
The sum() function can add numbers generated by range().
3fill in blank
hardFix the error in the code to correctly sum the list elements.
Python
values = [10, 20, 30] total = sum[1]values print(total)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using square brackets which are for lists, not function calls.
Using curly braces or angle brackets which are invalid here.
โ Incorrect
The sum() function requires parentheses around its argument.
4fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 letters.
Python
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using the word itself instead of its length.
Using the wrong comparison operator like <= which selects shorter words.
โ Incorrect
We use len(word) to get the length and filter words with length greater than 3 using >.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values greater than 10.
Python
data = {'a': 5, 'b': 15, 'c': 20}
result = { [1]: [2] for k, v in data.items() if v [3] 10 }
print(result) Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using original keys without uppercase.
Using wrong comparison operators like < instead of >.
Using keys instead of values in the dictionary.
โ Incorrect
The keys are converted to uppercase with k.upper(), values are v, and filtered where v > 10.