Question

Please respond in Python code Write a function adder() to add variable number of integers. The...

Please respond in Python code

Write a function adder() to add variable number of integers. The function should take *args as parameter. In the function body, the arguments should be added. The user should call the function as below: adder(3,5) adder(4,5,6,7) adder(1,2,3,5,6) and the output should be: 8 22 17 This lab does not require to enter any input.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM ANSWER:

def adder(*args):
# *args indicate a variable number of arguments stored in a tuple
add=0
for i in args: #iterates through the tuple and adds numbers in a tuple
add=add+i
return add

print(adder(3,5)) #function call
print(adder(4,5,6,7))
print(adder(1,2,3,5,6))
#if any syntactic or indentation errors please verify with the below screenshots

PROGRAM SCREENSHOT:

PROGRAM OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Please respond in Python code Write a function adder() to add variable number of integers. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT