Detailed python output Fibonacci sequence

Source: Internet
Author: User
This article is a detailed description of the Python output Fibonacci sequence

def Recur_fibo (n): "" "   recursive function   output Fibonacci sequence" "   if n <= 1:       return n   Else:       return (Recur_fibo (n-1) + Recur_fibo (n-2) # get input nterms = Int (input ("How many items do you want to output?")) # Check that the number entered is correct if nterms <= 0:   print ("input positive") Else:   print ("Fibonacci sequence:") for I in   Range (nterms):       print ( Recur_fibo (i))
# outputs the first 20 Fibonacci sequences to the list A = 0b = 1i = 0fibo = []while True:        i + = 1        If I <=:                fibo.append (a)                fibo.append ( b)                A + = b                B + = a        else:                print (Fibo)                print (len (Fibo))                break
Related Article

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.