vicuna-13b· LMSYS
Arena Human Preference 55K
Write a simple Python function to calculate the factorial of a given positive integer.
- User
Write a simple Python function to calculate the factorial of a given positive integer.
- Assistant
Sure! Here is a simple Python function to calculate the factorial of a given positive integer:
def factorial(n): # If the input is 0, return 1 if n == 0: return 1 # Otherwise, multiply n by the factorial of n-1 else: return n * factorial(n-1)To use this function, you would call it with a positive integer as the argument, like this:
result = factorial(5)This would calculate the factorial of 5, which is 120, and store the result in the
resultvariable.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.