Editor

Sum All Numbers

Intermediate · Write the code · from Python *args, **kwargs, Default Values, and Keyword Arguments

From the lesson: Python *args, **kwargs, Default Values, and Keyword Arguments

Think about ordering coffee. You always need to pick a size - that's required. But extras like oat milk, an extra shot, or caramel drizzle? Those are optional. You only mention them when you want them.

Read the lesson

Write a function called sum_all that uses *args to accept any number of numeric arguments and returns their sum. If no arguments are given, return 0.

# Define your function here
# Test it
print(sum_all(1, 2, 3))
print(sum_all(10, 20))
print(sum_all())

What Check runs

Your code runs first, then each of these lines. The output must match exactly.

RunsExpected output
print(sum_all(1, 2, 3))6
print(sum_all(10, 20))30
print(sum_all())0

More Function Arguments exercises

All Python exercises · 50 practice problems · Functions quiz