0
Print True if n is prime?
is_prime = True for i in range(2,n): if n%i == 0: #blank# print(is_prime) Can you fill in the #blank# line so the code will only print True if n is prime?
5 Respuestas
0
exit()
0
If you want to print False, whenever n is not a prime then do following-
is_prime = False
break
Here "break" statement will terminate the loop and print statement will execute, because there is no need for checking higher values of i anymore.
0
not any([n%i==0 for i in range(2,n)])
0
is_prime = True
for i in range(2,n):
if n%i == 0:
if n > 1:
print("False")
break
else:
print(is_prime)
0
is_prime = False