+ 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 #####
6 Answers
+ 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.
+ 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
+ 3
Thanks, now I get the code!
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).
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
0
correct answer is 13