7 Respuestas
+ 1
Simply a function that will continue to call itself and repeat its returned value is a recursion.
And i suggest you google this for more information.
+ 1
def factorial(x):
if x<=1:
return 1
else:
return x*factorial(x-1)
Ok we have a simple function that takes x as an argument and it will return this line x*factorial(x-1) which means that factorial(5) will return 5*factorial(5 - 1) which means 5 * factorial(4) so factorial(4) is called and will repeat this line x*factorial(x-1) = 4 * (4-1) = 4 * 3 = 3 * 2 = 2 * 1 = so it is 5 * 4 * 3 * 2 * 1 = 120 i hope you undrestand this code now.
0
EXPLAIN PLEASE
0
Thanks... i need explanation with code
0
def tri_recur(k):
if(k>0):
res = k + tri_recur(k-1)
print(res)
else:
res = 0
return res
tri_recur(6)
0
Oussama Ben Sassi Pls explain using this.