generate functionTue, 07 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. Solve with a while loop

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' is_prime(4)

Questions about programming?Chat with your personal AI assistant