Skip to content
Exercise · Loops · lesson 7 of 7

Exercise: prime number

Write a function is_prime(n) that returns True if n is a prime number and False otherwise. A prime number is greater than 1 and divides evenly only by 1 and by itself.

  • is_prime(97) → True
  • is_prime(91) → False
  • is_prime(2) → True

Constraints: n is an integer from 0 to 10000; the numbers 0 and 1 are not prime.

Do not add extra imports unless the task says so explicitly.

is_prime.py — python
python · 3 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way