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?

20th Apr 2020, 12:12 PM
Kriti Parashar
6 odpowiedzi
0
exit()
20th Apr 2020, 12:32 PM
ANJALI SAHU
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.
20th Apr 2020, 12:47 PM
Vijay Meena
0
not any([n%i==0 for i in range(2,n)])
11th Jun 2020, 11:58 AM
Simran Chhetija
Simran Chhetija - avatar
0
is_prime = True for i in range(2,n): if n%i == 0: if n > 1: print("False") break else: print(is_prime)
9th Jul 2020, 5:43 AM
Ak K
Ak K - avatar
0
is_prime = False
9th Mar 2021, 5:16 AM
Kader Dangi
Kader Dangi - avatar