Prime Number
Write a short script that determines whether a given number is a prime number.
Remember, a prime number is a natural number greater than 1 that is only divisible with zero remainder by the number 1, and itself. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, …
For now you don’t have to implement a fancy algorithm for testing primeness (e.g. Sieve of Eratosthenes). For now, it’s ok to implement a simple, brute force method.
Do not use a function you find on the internet or a built-in function (such as MATLAB’s isprime()
function or SymPy’s isprime()
function) to test primeness. The purpose of this exercise is for you to write your own code from scratch.
Hint: you will probably use a built-in modulo operation to test whether the remainder is zero after dividing a number N by another number i.
Your program should run like so:
Enter a number: 7 The number 7 is prime
and:
Enter a number: 12 The number 12 is not prime