gpt-4-0314· OpenAI
Arena Human Preference 55K
Write a Python program to find the nth Fibonacci number using dynamic programming.
- User
Write a Python program to find the nth Fibonacci number using dynamic programming.
- Assistant
Here is a Python program to find the nth Fibonacci number using dynamic programming with a technique called memoization:
def fibonacci(n, memo={}): if n == 0: return 0 elif n == 1: return 1 elif n in memo: return memo[n] else: memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo) return memo[n] n = int(input("Enter the value of n: ")) result = fibonacci(n) print(f"The {n}th Fibonacci number is: {result}")To run the program, input the value of n and the program will output the nth Fibonacci number using dynamic programming.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.