Do I read this code wrong? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Do I read this code wrong?

#####Python #### What’s the result of this code? triple = lambda x: x * 3 add = lambda x, y: x + y print(add(triple(3, 4)) ######In this line of code I entered the value’s of x in the first two lines. So I get 3*3=9 for the first x and for the second x I was pondering for awhile. To calculate that I need the value of y and I couldn’t find any value for that in the code so I assumed that it would return as a 0. Therefore for the second x I came up with 4+0=4. But what I don’t get is why the code continues as 9+4.. Because I would have read 9*4.. https://code.sololearn.com/W8PUh7zJ1kQZ/?ref=app #####

20th Aug 2018, 5:50 PM
Wilson Chong
Wilson Chong - avatar
6 Antworten
+ 4
What is the result of this code? triple = lambda x: x * 3 add = lambda x, y: x + y print(add(triple(3), 4)) The Correct answer is 13.
10th Apr 2020, 10:48 AM
Bibek Subedi
+ 3
Wilson Chong I think we have a problem with that code, now I understand your confusion, the 'triple' expected one argument passed, but two was passed instead => 'triple(3,4)'. I guess the correct form of the code should be along these lines: triple = lambda x: x * 3 add = lambda x, y: x + y print(add(triple(3), 4)) Here, as you see, 'triple' is called with 1 argument (3), and the 'add' is called with 2 arguments, first argument is return value of 'triple(3)' which is 9, and second argument is 4. This outputs 13 (9+4). Hth, cmiiw
20th Aug 2018, 8:02 PM
Ipang
+ 3
Thanks, now I get the code!
20th Aug 2018, 8:30 PM
Wilson Chong
Wilson Chong - avatar
0
What is the result of this code? triple = lambda x: x * 3 add = lambda x, y: x + y print(add(triple(3), 4)) Ans: 'triple' is called with 1 argument (3), and the 'add' is called with 2 arguments, first argument is return value of 'triple(3)' which is 9, and second argument is 4. This outputs 13 (9+4).
6th Dec 2020, 3:42 AM
IRFAN KHAN
IRFAN KHAN - avatar
0
question : What is the result of this code? program : triple = lambda x: x * 3 add = lambda x, y: x + y print(add(triple(3), 4)) output : 13
28th May 2021, 11:54 AM
Madhavareddy
Madhavareddy - avatar
0
correct answer is 13
24th Jul 2021, 6:03 AM
Judson Leo
Judson Leo - avatar