Python: Recursive

Source: Internet
Author: User

Two basic elements of recursion:

(1) boundary condition: determines when recursion is terminated, also known as a recursive exit. (n = 1)
(2) recursive mode: The big problem is how to break it down into small problems, also known as recursive bodies.   (N (n-1)! N>1)

Example: Accumulation

1 n = 02 for in range (1,6):3         n + = I4  Print(n)

The output is:

15

Example: Recursion

1 def Fun (n): 2     if or n==1:3         return 14     else:5          return n*fun (n-1)6print (Fun (5))

The output is:

120

Python: Recursive

Contact Us

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.