Challenge - 5 Problems
Sum Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Sum of a list with a start value
What is the output of this code?
numbers = [1, 2, 3, 4] result = sum(numbers, 10) print(result)
Python
numbers = [1, 2, 3, 4] result = sum(numbers, 10) print(result)
Attempts:
2 left
๐ก Hint
Remember that sum() can take a second argument as the starting value.
โ Incorrect
The sum() function adds all items in the list and then adds the start value 10. So, 1+2+3+4=10 plus 10 equals 20.
โ Predict Output
intermediate2:00remaining
Sum of a tuple without start value
What is the output of this code?
values = (5, 10, 15) print(sum(values))
Python
values = (5, 10, 15) print(sum(values))
Attempts:
2 left
๐ก Hint
sum() adds all numbers in the tuple by default starting from zero.
โ Incorrect
The sum of 5 + 10 + 15 is 30.
โ Predict Output
advanced2:00remaining
Sum of a list of strings
What error does this code raise?
words = ['a', 'b', 'c'] print(sum(words))
Python
words = ['a', 'b', 'c'] print(sum(words))
Attempts:
2 left
๐ก Hint
sum() works only with numbers by default.
โ Incorrect
sum() cannot add strings because it expects numbers, so it raises a TypeError.
โ Predict Output
advanced2:00remaining
Sum of a list with a non-zero start value and negative numbers
What is the output of this code?
nums = [-1, -2, -3] print(sum(nums, 5))
Python
nums = [-1, -2, -3] print(sum(nums, 5))
Attempts:
2 left
๐ก Hint
sum() adds all numbers starting from the start value.
โ Incorrect
Sum of -1, -2, -3 is -6. Adding start value 5 gives 5 + (-6) = -1.
๐ง Conceptual
expert2:00remaining
Sum() with a list of lists
What error does this code raise?
list_of_lists = [[1, 2], [3, 4]] print(sum(list_of_lists))
Python
list_of_lists = [[1, 2], [3, 4]] print(sum(list_of_lists))
Attempts:
2 left
๐ก Hint
sum() tries to add lists using + operator but needs a start value for lists.
โ Incorrect
sum() by default starts at 0, which cannot be added to a list, causing a TypeError.