+ 1

# Functional arguments **args

Given a function that takes 2 arguments and returns their sum. But we get an error when we want to sum more than 2 numbers. Change the function and complete the code so that the function sums as many numbers as are input. *args are accessible as the tuple args in the body of the function, so you can iterate through its items. def adder(x, y): print(x+y) adder(2, 3) adder(2, 3, 4) adder(1, 2, 3, 4, 5)

13th Apr 2021, 2:25 AM
Veena Tirmal
+ 5
Hi! Try to point out what you have problem with, instead of posting the whole assignment. 1. You have to figure out how functions works with a variable number of arguments. You can use * in front of the argument when you implement your function for that: def f(*args): print(args) 2. You have to find a function that sum more than two arguments. You can use the bult-in sum() for that. 3. You have to put 1. and 2. together.
13th Apr 2021, 3:01 AM
Per Bratthammar
+ 2
I don't understand why is everyone giving lectures about try first do this do that. I posted coz it's been 3 days n I watched all args related videos n still I'm not able to understand. And I posted the full assignment for the ease of solving. When i posted only the question I was asked to post the whole question. The only thing you have to do is answer the question if you want to or don't if you don't want. I'm here to learn I know there's no use of getting just a certification Per Bratthammar
13th Apr 2021, 3:21 AM
Veena Tirmal
+ 2
Hi, again! In your case it is because you donâ€™t pointed out your question. The assignment are not a question, nor are the code lines. And in the heading you write about **args, that are about key word arguments, and not necessary here. I think there is for a good a reason people here not just publish the whole soloution to different assignments, but instead answare them in form of hints. A qustion about the assignment could in your case be more realated to the actual problem you have. And a good answer would give you the hints to solve the problem, by you. Thatâ€™s what I think, and why I answare your not very clear question in the way I did.
13th Apr 2021, 3:48 AM
Per Bratthammar
+ 1
Jan Markus thank you sir for forgiving meðŸ˜„ sir you could make an example for your learning but not make it public, while giving hints only to the questioners.
13th Apr 2021, 8:48 AM
Bot
0
Things to Remember: https://www.dunkinrunsonyou.run/ *args and **kwargs are special keyword which allows function to take variable length argument. *args passes variable number of non-keyworded arguments and on which operation of the tuple can be performed.
26th Dec 2022, 12:16 PM
Guyer JHU
- 2
sorry Jan Markus sir, but i have to downvote your answer for direct solution without hints, explanations, or feedback.ðŸ˜¥
13th Apr 2021, 5:12 AM
Bot