Here's a Python code to check if a number is prime or not:
main.py390 chars22 lines
The code first checks if the number is less than or equal to 1, because any number less than or equal to 1 is not a prime. Then, it checks if the number is 2 or 3, in which case the number is a prime. If the number % 2 == 0 or number % 3 == 0, then the number is not a prime. After this, we check if the number is divisible by any number from 5 to sqrt(n) with a step of 6. We can skip checking multiples of 2 and 3 because we've already done that. If the number is not divisible by any odd number between 5 and sqrt(n), then it is a prime number.
gistlibby LogSnag