How can I build a recursive function in python? Sep 19, 2018 in Python 146 views

## 1 answer to this question.

I'm wondering whether you meant "recursive". Here is a simple example of a recursive function to compute the factorial function:

```def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)```

The two key elements of a recursive algorithm are:

• The termination condition: n == 0
• The reduction step where the function calls itself with a smaller number each time: factorial(n - 1) answered Sep 19, 2018 by
• 57,700 points

## how can i use the sum function in a python list?

If there is list =[1,2,4,6,5] then use ...READ MORE

## How can I use the sleep function in a python program?

You can use sleep as below. import time print(" ...READ MORE

## How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

## How can I create a new file in Python?

You can try the below code which ...READ MORE

## how do i change string to a list?

suppose you have a string with a ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## how do i use the enumerate function inside a list?

can you give an example using a ...READ MORE