+ 4

How is this posible?

def func(num): g = (lambda x:1 if x==1 else x*g(x-1)) return g(num) print(func(4)) Output --> 24

16th Jun 2020, 3:13 PM
Brian Alexander Lazo Rodriguez
Brian Alexander Lazo Rodriguez - avatar
3 Antworten
+ 1
First value of x is 4 In first step : the else statement will execute 4*g(3) In second step : the else statement will execute too 4*3*g(2) In third step: which happen in first and second will happen here too 4*3*2*g(1) Last step: the if statement will execute and return 4*3*2*1 which equal 24 Brian Lazo
16th Jun 2020, 8:29 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 4
Thanks MuhammadⓂ️🥇🛡️✔️ !! You are awesome ! I'm very grateful to You
17th Jun 2020, 6:03 AM
Brian Alexander Lazo Rodriguez
Brian Alexander Lazo Rodriguez - avatar
+ 2
you're welcome💝💚💞🌸🌹😊 BALRV 🚭
17th Jun 2020, 9:15 AM
Muhammad Galhoum
Muhammad Galhoum - avatar