I made this function to check whether a number was prime or not.
This was developed using codepad.org to test it during my 15 minute study hall. So it's simple, but it does work as far as I can see.
This was developed using codepad.org to test it during my 15 minute study hall. So it's simple, but it does work as far as I can see.
Code:
#!/usr/bin/env python
def isprime(n):
if n > 10:
if n%2 == 0 or n%3 == 0 or n%4 == 0 or n%5 == 0 or n%6 == 0 or n%7 == 0 or n%8 == 0 or n%9 == 0 or n%10 == 0:
return False
else:
return True
if n <= 10:
if n == 2 or n == 3 or n == 5 or n == 7:
return True
if n == 1 or n == 4 or n == 6 or n ==8 or n == 9 or n == 10:
return False