# Xuefeng Liao Website: Learning python functions-recursive functions (iv)

Source: Internet
Author: User

`#inside a function, you can call other functions. If a function calls itself internally, the function is a recursive function#calculate factorial n! = 1 x 2 x 3 x ... x n, denoted by the function fact (n), you can see:#fact (n) = n! = 1 x 2 x 3 x ... x (n-1) x n = (n-1)! x N = fact (n-1) x n#the advantage of using a recursive function is that the logic is simple and clear, and the disadvantage is that too-deep calls cause a stack overflow. deffact (n):ifN==1:        return1returnn * Fact (n-1)Print('fact (1) =', Fact (1))Print('fact (5) =', Fact (5))Print('fact (Ten) =', Fact (10))#To move a Hanhannotta using a recursive function:defMove (n, a, B, c):ifn = = 1:        Print('Move'A' -', c)Else: Move (n-1, A, C, b) Move (1, A, B, c) move (n-1, B, A, c) move (4,'A','B','C')`

Xuefeng Liao Website: Learning python functions-recursive functions (iv)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.