Answers for "how to use recursion in python"

5

recursive function in python

def factorial(x):
    """This is a recursive function
    to find the factorial of an integer"""

    if x == 1:
        return 1
    else:
      	result = x * factorial(x-1)
        return ()


num = 3
print("The factorial of", num, "is", factorial(num))
Posted by: Guest on January-17-2021
4

recursion in python

def rec(num):
    if num <= 1:
        return 1
    else:
        return num + rec(num - 1)

print(rec(50))
Posted by: Guest on March-03-2021
2

recursion in python

def yourFunction(arg):
    #you can't just recurse over and over, 
    #you have to have an ending condition
    if arg == 0:
        yourFunction(arg - 1)
        
    return arg
Posted by: Guest on March-14-2020
0

recursion python examples

void A(n){
    if(n>1) // Anchor condition
    {
       return A(n-1);
    }
}
Posted by: Guest on May-22-2021

Code answers related to "how to use recursion in python"

Python Answers by Framework

Browse Popular Code Answers by Language