mardi 2 août 2016

I have written the following code in python( does not work for -ve values):

def isprime(x):
 for a in range(2,(x//2)+1):
   if((x<=0) or (x%a==0)):
     return(False)
 return(True)


This does not work for negative values . for eg: isprime(-3) returns True but it has to return False. please help.

Aucun commentaire:

Enregistrer un commentaire