+ 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

31st Oct 2016, 3:59 PM
victorious victor
victorious victor - avatar
3 odpowiedzi
+ 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
1st Nov 2016, 4:13 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
😀 24 simple is that
19th Nov 2016, 2:45 PM
Hetbo.net
Hetbo.net - avatar
+ 1
I think it's 24, x=2*2*3*2
31st Oct 2016, 5:14 PM
Wombato Wom
Wombato Wom - avatar