gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
Write me a function in python that can calculate the factorial of a given number, x
- User
Write me a function in python that can calculate the factorial of a given number, x
- Assistant
Certainly! Here’s a simple Python function to calculate the factorial of a given number
x:def factorial(x): if x < 0: return "Factorial is not defined for negative numbers." elif x == 0 or x == 1: return 1 else: result = 1 for i in range(2, x + 1): result *= i return result # Example usage: print(factorial(5)) # Output: 120Let me know if you’d like a recursive version or have any other requirements!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.