Math Tools

Interactive utilities to explore mathematical concepts and solve problems.

Interactive Math Utilities

Explore these Python code snippets to check prime numbers and generate prime factors for any positive integer.

1

Prime Number Checker

Check if a number is prime or not. A prime number is a natural number greater than 1 that is only divisible by 1 and itself.

2

Prime Factor Generator

Generate all prime factors of a number. Prime factors are the prime numbers that multiply together to give the original number.

Python: Prime Number Checker

value = int(input("Enter a number: "))

# define a flag variable
flag = False

if value == 0 or value == 1:
    print(value, "is not a prime number")
elif value > 1:
    # check for factors
    for n in range(2, value):
        if (value % n) == 0:
            # if factor is found, set flag to True
            flag = True
            # break out of loop
            break

    # check if flag is True
    if flag:
        print(value, "is not a prime number")
    else:
        print(value, "is a prime number")

Python: Prime Factor Generator

value = int(input("Enter a number: "))

def prime_factors(n):
    factors = []
    divisor = 2
    while n > 1:
        while n % divisor == 0:
            factors.append(divisor)
            n //= divisor
        divisor += 1
    return factors

print("Prime factors are:", prime_factors(value))

More Math Resources

Explore these additional resources to enhance your mathematical understanding.

Math Formula Sheet

Access a comprehensive collection of mathematical formulas for algebra, geometry, calculus, and more.

View Formulas

Practice Problems

Sharpen your skills with this collection of past MAT papers from Oxford University entrance exams.

Start Practicing

Video Tutorials

Watch clear explanations of key mathematical concepts with step-by-step visual guidance.

Watch Tutorials