# Prime Number Check in Python

#### Did you know?

A prime number is a number that has exactly two factors (1 and itself). Which means that a prime number can be divided evenly only by 1, or itself. A prime number must be a whole number greater than 1.

2, 3, 5, 7, 11, 13, 17… are all examples of prime numbers.

Write a program that prompts the user to enter a number between 1 and 9999. The program will inform the end-user whether their number is a prime number or not.

#### Hint:

In Python you can easily calculate the remainder of a division using the % sign.

For instance 7 % 2 would return 1.

So to check if a number “a” can be divided evenly by another number “b” you can check if the remainder of a/b is null using if a%b==0

#### Solution

So let’s look at the following code used to check if a number is a prime number or not.

#### Extended Challenges

1. Tweak this code to display all the prime numbers between 1 and 9999.
2. Write another program that takes a user input and find out if the number being entered is either odd or even.
[pms-restrict display_to=”not_logged_in” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ message=” “]

#### Solution...

You are viewing this solution as part of your full membership subscription!

Python Code

#### Python Code

```#Prime Numbers List - www.101computing.net/prime-number-check-in-python/

#A function to check if a number is a prime number or not
def isPrime(number):
if number<2:
return False
prime=True
for i in range(2,number):
if number % i ==0:
prime=False
break
return prime

print("Prime numbers between 1 and 999:")
for i in range(2,1000):
if isPrime(i):
print(i)
```
[/pms-restrict]

Did you like this challenge?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

As you found this challenge interesting...