0

1.4kviews

Write a python program to check if the entered no is prime or not

**1 Answer**

0

1.4kviews

Write a python program to check if the entered no is prime or not

0

183views

written 2.5 years ago by |

Explanation:-

- Take a no as an input from the user & store the number in variable number then and pass on this number to a prime function.
- Check if the number is greater then 1 if not then show a message representing enter the valid number.
- Iterate over the range from 2 to number check if the number is divisible from any of these numbers if yes then prime as number is not a prime no else prime the entered number is prime.

Code:-

```
number = int(input("Enter a number: "))
def prime(number):
if number > 1:
for i in range(2,number):
if (number % i) == 0:
print(number,"is not a prime number")
break
else:
print(number,"is a prime number")
else:
print("Enter valid number")
prime(number)
```

Output:-

ADD COMMENT
EDIT

Please log in to add an answer.