0

Good day people, pls i need explanation on python recursion function. With code example.

Python Recursion function.

15th Apr 2020, 12:00 AM
Nwachukwu Bright
Nwachukwu Bright - avatar
7 odpowiedzi
15th Apr 2020, 12:26 AM
Cmurio
Cmurio - avatar
+ 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.
15th Apr 2020, 1:16 AM
Oussama Ben Sassi
Oussama Ben Sassi - avatar
+ 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.
15th Apr 2020, 1:31 AM
Oussama Ben Sassi
Oussama Ben Sassi - avatar
0
EXPLAIN PLEASE
15th Apr 2020, 12:40 AM
Nwachukwu Bright
Nwachukwu Bright - avatar
0
Thanks... i need explanation with code
15th Apr 2020, 1:19 AM
Nwachukwu Bright
Nwachukwu Bright - avatar
0
def tri_recur(k): if(k>0): res = k + tri_recur(k-1) print(res) else: res = 0 return res tri_recur(6)
15th Apr 2020, 1:45 AM
Nwachukwu Bright
Nwachukwu Bright - avatar
0
Oussama Ben Sassi Pls explain using this.
15th Apr 2020, 1:45 AM
Nwachukwu Bright
Nwachukwu Bright - avatar