Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 7

Create a function that accepts any number of args

Easy

6 minute session

Summary

Use *args to accept a variable number of positional arguments and process them.

Problem statement

Implement sum_all(*args) which accepts zero or more numeric positional arguments and returns their sum. The function should handle integers and floats and return 0 when called with no arguments.

Task

Write a function sum_all that accepts any number of positional numeric arguments and returns their sum. If no arguments are given, return 0.

Examples

Sum three numbers

Input

sum_all(1, 2, 3)

Output

6

Explanation

1 + 2 + 3 equals 6.

Input format

A variable number of positional numeric arguments (ints or floats).

Output format

A single number: the sum of the provided arguments (0 if none).

Constraints

Do not use external libraries. The function should work with int and float inputs.

Samples

Sample input 0

sum_all()

Sample output 0

0

Explanation 0

No arguments provided, so the sum is 0.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

07:45 PM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.