0
0
Pythonprogramming~10 mins

sum() function in Python - Interactive Code Practice

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

Complete 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'
Amin
Blen
Cmax
Dsum
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.
2fill in blank
medium

Complete 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'
Amax
Bsum
Clen
Dmin
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.
3fill in blank
hard

Fix 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'
A{ }
B[ ]
C( )
D< >
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.
4fill in blank
hard

Fill 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'
Alen(word)
Bword
C>
D<=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the word itself instead of its length.
Using the wrong comparison operator like <= which selects shorter words.
5fill in blank
hard

Fill 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'
Ak.upper()
Bv
C>
Dk
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.