generate functionThu, 02 Mar 2023

Given a natural number N. Determine if it is prime. A natural number N is called prime if it has only two divisors: one and the number N itself. As an answer, print "Yes" if the number is prime, "No" otherwise.

def is_prime(n): if n == 1: return "No" i = 2 while i * i <= n: if n % i == 0: return "No" i += 1 return "Yes"

Questions about programming?Chat with your personal AI assistant