Python recursive function Fibonacci sequence

Asked 1 years ago, Updated 1 years ago, 144 views

n=int (enter the N value of the "Fibonacci sequence F(N)" --> : ")))   

def fibo(n):

    # Recursive functions require escape conditions.

    if n < 3 :
        return 1
    else : 
        return fibo(n-2) + fibo(n-1)

# Find the Fibonacci sequence to index n
def fibo_list(n):
    for i in range(n):
        print(fibo(i), end= " ")
print(fibo(n))

I even used a recursive function to make the Fibonacci sequence count For example, if you set the value of n to 7, at the end, F(7) = 13 What should I do to make F(n) appear in front of the value in this way?

python recursive fibonacci

2022-09-21 21:19

1 Answers

The title is about the Fibonacci sequence recursive function, and in fact, what you're asking is how to use Python prints!

# Method 1
print "fibo(1) =", fibo(1)
# Method 2
print("fibo(7) = " + str(fibo(7)))

Go back to the demo.


2022-09-21 21:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.