137. Python Program to Check a Prime Number Using a Function
Mediumreturn
Overview
Return a boolean, and return early from inside a loop.
Problem Statement
A prime number is a whole number bigger than 1 that can only be divided evenly by 1 and by itself. 2, 3, 5 and 7 are prime; 4, 9 and 1 are not.
Write a function is_prime(n) that returns True if n is prime and False if it isn't. Then read a whole number and print one of these, like this for 7:
7 is prime
or, for 9:
9 is not prime
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
One whole number from 1 to 1000. Example:
7
Output
The output for that example:
7 is prime
The tests try 5 different inputs, including 1 and 2.