+ 2

question about function?

How to solve this? def fun (x): if x == 1: return 1 else: return x * fun (x-1) print (fun(5))

4th Aug 2020, 12:18 PM
Asma Al-Samman
2 odpowiedzi
+ 2
Asma Al-Samman when x==5, fun=5*fun(4)=5*4*fun(3)=5*4*3*fun(2)=5*4*3*2*1=120
4th Aug 2020, 1:03 PM
Petr
+ 3
Calling such a case a recursive function, I recommend you read about it and then I'm sure you can answer the question yourself
4th Aug 2020, 12:30 PM
Panda🐼🐼🐼
Panda🐼🐼🐼 - avatar