Python 3 Tutorial: How To Use Recursive Functions

preview_player
Показать описание
In this Python 3 Tutorial, we will talk about recursive functions these are functions that call themself.

Be sure to like, share and comment to show your support for our tutorials.

=======================================
======================================
Рекомендации по теме
Комментарии
Автор

You said that the function could be better performed with a while loop. I made a while loop to mimic the what the recursive function performed. Same result except that the last iteration returns "None" after the "n is equal to one" statement. How can I prevent it from returning "None" at the end (besides the recursive function you already showed)?

def total(n):
while n:
if n == 1:
print("Loop terminated. \"N\" is equal to one")

else:
print(n)
n -=1


print(total(10))

Result:
10
9
8
7
6
5
4
3
2
Loop terminated. "N" is equal to one
None

mountainscott
visit shbcf.ru