gpt-4o-mini-2024-07-18· openai
WildChat-4.8M
Make 10 line Python
- User
Make 10 line Python
- Assistant
Certainly! Below is a simple Python program that calculates the factorial of a number provided by the user. The program ensures it is concise, fitting into 10 lines:
def factorial(n): if n == 0: return 1 return n * factorial(n - 1) try: num = int(input("Enter a non-negative integer: ")) if num < 0: raise ValueError print(f"The factorial of {num} is {factorial(num)}.") except ValueError: print("Please enter a valid non-negative integer.")This code includes a recursive function to compute the factorial, handles input validation, and outputs the result.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.