Explain how python outputs the Fibonacci series

Source: Internet
Author: User
This article details python output the Fibonacci series. This article details python output the Fibonacci series.

Def recur_fibo (n): "recursive function output Fibonacci sequence" if n <= 1: return n else: return (recur_fio (n-1) + recur_fio (n-2 )) # obtain the input nterms = int (input ("How many items do you want to output? ") # Check whether the entered number is correct if nterms <= 0: print (" input positive number ") else: print (" Fibonacci sequence: ") for I in range (nterms): print (recur_fibo (I ))
# Output the first 20 Fibonacci series to the list a = 0b = 1i = 0 fibo = [] while True: I + = 1 if I <= 10: fibo. append (a) fibo. append (B) a + = B + = a else: print (fiber) print (len (fiber) break

The above is a detailed description of the Fibonacci series output by python. For more information, see other related articles in the first PHP community!

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.