Python Fibonacci Sequence Exercises

Source: Internet
Author: User

#CODING=GBK#Iterative Method---1defFibonacci (N):ifn = = 0orn = = 1:        returnNElse: A=0 B= 1 forIinchRange (n-1): T=a A=b b= A +Treturnb Number= eval (Input ("Please enter the Fibonacci sequence you want to calculate \ n")) cc=Fibonacci (number)Print(CC)#Iterative Method---2deffibonacci2 (n):Print("N is"+str (n)) terms= [0,1] I= 2 whileI <=N:terms.append (Terms[i-1] + terms[i-2]) I= i + 1returnTerms[n]number= eval (Input ("Please enter the Fibonacci sequence you want to calculate \ n")) cc=fibonacci2 (number)Print(CC)#Recursive method---1deffibonacci1 (n):Print('N is'+str (n))ifn = = 0orn = = 1 :        returnNElse :            returnFIBONACCI1 (n-1) + FIBONACCI1 (n-2) number= eval (Input ("Please enter the Fibonacci sequence you want to calculate \ n")) cc=fibonacci1 (number)Print(CC)

The above code refers to someone else, and the problems encountered are:

1 error:syntaxerror:non-utf-8 code starting with ' \xb5 '

The reason is that because the code contains non-UTF-8 characters, you can add a command to the first line of code:

# CODING=GBK

Python Fibonacci Sequence Exercises

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.