Editor settings

General settings

Save settings

Learn to program with Python

Is this a prime number #

Write a function that takes a number as input and determines whether it is a prime number. A prime number is a whole number greater than 1 whose only factors are 1 and itself.

Examples:

  • 2 is a prime number because 2 is divisible only by 1 and 2.
  • 3 is also a prime number because it is divisible only by 1 and 3.
  • 4 is not a prime number because it is divisible by 1, 2, and 4.
  • 25 is not a prime number because it is divisible by 1, 5, and 25.
  • 100 is not a prime number because it is divisible by 1, 2, 4, 5, 10, 20, and 50.
  • 997 is a prime number because it is divisible only by 1 and 997.

Tests #

  • is_prime(2) should return True
  • is_prime(17) should return True
  • is_prime(97) should return True
  • is_prime(121) should return False
  • is_prime(999) should return False
  • is_prime(10007) should return True
  • is_prime(99991) should return True
  • is_prime(100003) should return True
  • is_prime(1000000) should return False
Output will be displayed here