Back to resources

Defining a function to test whether a positive integer greater than 1 is prime in Python

There is no function built-in Python function to test an integer for primality. Here’s some guidance to overcome this challenge.

  • document icon

    Advice sheet

Related resources

Popular

Ritangle 2025

Ritangle 2025 took place from 8 October to 5 December 2025, with 1,854 teams taking part.
Popular

MEI Conference 2025 Session Resources

Can you ‘control minds’ and make people do what you want – or does the maths help you?

Ritangle 2024

Questions and answers from our Ritangle 2024 competition

Proving the Pythagorean Theorem

Explore the Pythagorean Theorem in ancient texts in order to better appreciate how maths has developed in a range of diverse cultures.
Skip to content