MIT Python Fourth Lesson function abstraction and recursion The classic case of the last three minutes recursion: Fibonacci sequence

Source: Internet
Author: User
Fibonacci sequence Fibonacci Sequence, also known as the Golden section of the series, refers to such a series: 0, 1, 1, 2, 3, 5, 8, 13, 、...... Mathematically, the Fibonacci sequence is defined as a recursive method: F (0) =0,f (1) =1,f (n) =f (n-1) +f (n-2) (n≥2,n∈n*)

There are a pair of one-month-old male and female rabbits, in another one months when mating rabbits, assuming they are born of two a male and female rabbit, at the end of the next month these two rabbits also have offspring is also a male and female, the question is how many rabbits will you have in a year? [Bared teeth] the third year was like going to Australia ...

def fib (x):     if or x==1:return 1    else:return fib (x-1) +fib (x-2)    >> > fib (233>>>) fib (75025>>> fib)

MIT Python Fourth Lesson function abstraction and recursion The classic case of the last three minutes recursion: Fibonacci sequence

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.