Computer Science, asked by rgs012070, 2 months ago

Write python Program to enter a number and to check if it is prime or not.( write input and output also please)​

Answers

Answered by anindyaadhikari13
1

Required Answer:-

Question:

  • Write a Python program to enter a number and check if it is prime or not.

Solution:

Here comes the program.

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

c=0

for i in range(1,n+1):

if n%i==0:

 c+=1

if c==2:

print(n,"is Prime.")

else:

print(n,"is not Prime.")

Explanation:

  • A number is said to be prime if it is only divisible by 1 and itself. Therefore, we can say that total factors of a prime number is 2 (1 and itself). In this program, we will simply count the number of factors of the entered number and if the value is 2, then it is a prime number else not.

See the attachment for output ☑.

Attachments:
Similar questions