Python code to calculate primorial
- User
Python code to calculate primorial
Assistant
Sure, here's some Python code to calculate the primorial of a given number:
pythondef is_prime(n): """ Returns True if n is prime, False otherwise. """ if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def primorial(n): """ Returns the primorial of n, which is the product of all prime numbers up to n. """ result = 1 for i in range(2, n + 1): if is_prime(i): result *= i return resultThe
is_primefunction checks if a given number is prime, and the function calculates the primorial of a given number by multiplying all prime numbers up to that number.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.