+ 1

Function inside funtion

Can someone help me understand the following please? I end up with something called 'RecursionError'. 1.def say_hello(): 2. say_hello() 3. 4.def count_to_10(): 5. for a in range(1, 11): 6. print(a) 7. 8.say_hello() 9.count_to_10() 10.say_hello()

29th May 2018, 6:03 PM
arbaaz
4 ответов
+ 4
A recursive function must have a base case, that is a condition that makes the function stops calling it itself. Yours does not. That is why you have an error. Look at all the recursive functions you have encountered and you will see that there is always a statement that makes the function stops calling itself.
29th May 2018, 6:26 PM
cyk
cyk - avatar
+ 3
The say_hello() function is calling itself indefinitely.. So it just goes on and on and that causes an error
29th May 2018, 6:14 PM
Danny
Danny - avatar
+ 2
Thank you all for your answers.
29th May 2018, 11:08 PM
arbaaz
0
sumply you create an infinity loop.
29th May 2018, 6:30 PM
Filip Dobeš