Python Prime Number Checker - Simple Code
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This code defines a simple function is_prime that determines whether a given number is prime. It first handles edge cases for 0, 1, and 2, then loops from 2 to the square root of the number, checking divisibility.
The square root optimization makes the function efficient by reducing the number of iterations needed. The code prints sample outputs for the numbers 5, 12, 37, 93, and 1567.
- 5 → True
- 12 → False
- 37 → True
- 93 → False
- 1567 → True