Your question is Iterative and Recursive Fibonacci. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
IDT services may use sequence calculations in scheduling and validation logic. Implement a function that computes the nth Fibonacci number using either an iterative or a recursive strategy.
Define the sequence as F(0) = 0, F(1) = 1, and F(n) = F(n - 1) + F(n - 2) for n > 1.
Your function must accept a non-negative integer n and a method string. If method is "iterative", compute the result with a loop. If method is "recursive", compute it with direct recursion. Return the Fibonacci value as an integer.
n, an integer from 0 through 30, and method, either "iterative" or "recursive".F(n).def fibonacci(n, method):