+ 2
What gets printed? d = lambda p: p * 2 t = lambda p: p * 3 x = 2 x = d(x) x = t(x) x = d(x) print x
3 Respostas
+ 3
The purpose of a question like this is to teach logical flow, so since an answer was posted here's the breakdown.
d = lambda p: p * 2
'd' is a function defined on the spot (they're called lambdas). It has one parameter: p. The function doubles p and returns it.
t = lambda p: p * 3
't' is a function defined on the spot. It has one parameter, p. The function triples p and returns it.
x = 2
Assign 'x' the value 2.
x = d(x)
d..."d"oubles x (p internally) and stuffs the value back into x.
x = t(x)
t..."t"riples x (p internally) and stuffs the value back into x.
x = d(x)
d...doubles x (p internally) and stuffs the value back into x.
print x
x was: 2
double it. 4
triple it. 12
double it. 24
+ 2
😀
24
simple is that
+ 1
I think it's 24, x=2*2*3*2