Problem No 7
Create a function that accepts any number of args
Easy≈ 6 minute session
Lesson guide
What this Python exercise practices
Create a function that accepts any number of args is a beginner practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 6 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Beginner
- Estimated time
- 6 minutes
Practice path
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.
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.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.