Problem 154512 · easy · Level 01 Prerequisites & Setup

Prime Check

functions · loops · primes

Write is_prime(n) that returns True if n is a prime number and False otherwise.

A prime is an integer greater than 1 whose only positive divisors are 1 and itself. Numbers below 2 are never prime.

Examples

Input:  n = 2
Output: True

Input:  n = 9
Output: False

Input:  n = 1
Output: False

Constraints

  • -10**9 <= n <= 10**9 + 7

Goals

  • Return a boolean from a function
  • Handle 0, 1 and negatives correctly
  • Stop testing at the square root
Starting Python…