Help! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help!

Hello can someone explain to me what is wrong with my code? This is the question: 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. This my code: #change the function def adder(x, y,*args): print(x+y) sum(args) adder(2, 3) adder(2, 3, 4) adder(1, 2, 3, 4, 5)

14th May 2021, 9:28 AM
Zhi Hong
Zhi Hong - avatar
4 Answers
+ 1
Hi! For better help to you, please, show us your code attempt! Thx!
14th May 2021, 9:30 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
distinguish between where is the task code and where exactly is your code?
14th May 2021, 9:31 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Yaroslav Vernigora sorry mb. This was the given code: #change the function def adder(x, y): print(x+y) adder(2, 3) adder(2, 3, 4) adder(1, 2, 3, 4, 5)
14th May 2021, 9:57 AM
Zhi Hong
Zhi Hong - avatar
0
Give list as function parameter instead of variables and output sum of elements of the list
14th May 2021, 2:09 PM
Ashish Kalla
Ashish Kalla - avatar