gpt-3.5-turbo-1106· OpenAI
Arena Human Preference 55K
Please provide code in Python that generates the nth fibonacci number.
- User
Please provide code in Python that generates the nth fibonacci number.
- Assistant
Certainly! Here's a simple Python function to generate the nth Fibonacci number using recursion:
pythondef fibonacci(n): if n <= 0: return "Invalid input" elif n == 1: return 0 elif n == 2: return 1 else: return fibonacci(n-1) + fibonacci(n-2) # Example usage: print(fibonacci(10)) # Outputs: 34This code defines a function
fibonaccithat takes an integernas input and returns the nth Fibonacci number. It uses recursion to calculate the Fibonacci number.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.