Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Prime Number Program

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Prime Number Program. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Write a function that determines whether a given integer is prime. A prime number is an integer greater than 1 that has exactly two positive divisors: 1 and itself.

Formal Specification

Implement is_prime(n) where n is an integer. Return True if n is prime, otherwise return False.

Constraints

  • -10^9 <= n <= 10^9
  • Return False for any n <= 1
  • The solution should be more efficient than checking every number from 2 to n-1

Function Signature

def is_prime(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output