#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