Prime Checker Function
Write a function is_prime(n) that returns True if n is a prime number, False otherwise, then read a number and print the result.
What the problem means: a prime number is a whole number greater than 1 with no divisors other than 1 and itself. Wrap that check inside a reusable function instead of writing it inline.
Approach: inside is_prime(n), return False for anything less than 2, then check whether any number from 2 up to n-1 divides n evenly.
Input: One line: a whole number n.
Output: One line: True or False.
17
True
- 1 <= n <= 100000
Hint 1
Numbers less than 2 are never prime — handle that first.
Hint 2
Loop from 2 up to n - 1; if any of them divides n evenly (n % i == 0), it's not prime.
Hint 3
print(is_prime(n)) will print exactly True or False, matching Python's own boolean text.
Wrap the primality check inside a function so it can be reused: is_prime(n) returns False immediately for n < 2, then loops i from 2 to n - 1, returning False the moment any i divides n evenly. If the loop finishes without finding a divisor, the number is prime.