python - How to make it run through my whole range? -


def isprimelike(n):     in range(2,n-1):         if pow(a,n,n) == a%n:             return true         else:             return false 

when check n given value check 2, decides if true or false , doesn't check rest of range. not sure how make check rest of range.

that's because you're using return inside if-else block. might want change return statement print 1 indicating if prime number or not.

if want return true if prime-like or false if @ least 1 not, following:

def isprimelike(n):     in range(2,n-1):         if pow(a,n,n) != a%n:             print('one element false')             return false     return true 

the print statement show something, it's not relevant.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -