gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
Make 10 line Python
- User
Make 10 line Python
- Assistant
Certainly! Here’s a simple 10-line Python script that defines a function to calculate the factorial of a number and then uses that function to print the factorial of a number provided by the user.
pythondef factorial(n): if n == 0 or n == 1: return 1 return n * factorial(n - 1) number = int(input("Enter a positive integer: ")) if number < 0: print("Factorial is not defined for negative numbers.") else: result = factorial(number) print(f"The factorial of {number} is {result}.")This script does the following:
- Defines a recursive function to compute the factorial.
- Prompts the user to enter a positive integer.
- Checks if the input is valid and computes the factorial if it is.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.