it says that the program returns true for x =0

It should work

def is_prime(x):
    prime= True
    for n in range(2,x-1):
        if x%n==0 or x<2:
            prime= False
    return prime


the if condition here:

if x%n==0 or x<2:

x<2 has no effect, given for values lesser then 2, the loop will not iterate.

also, range does not include its stop value, so why subtract one?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.