Search This Blog
Available Codings for Programming of C, C++, PYTHON, JAVA and HTML.
Welcome to Coding 4 Programming
- Get link
- X
- Other Apps
Labels
To check Prime Number | Function | Python
Python Program to check whether entered Number is Prime or Not through Function.
- def primef(num):
- if (num==1 or num==0):
- return False
- elif (num==2):
- return True
- else:
- c=1
- for i in range(2,num):
- if(num%i!=0):
- c+=1
- if(c==num-1):
- return True
- else:
- return False
- n=int(input("Enter Number to check Prime="))
- print(primef(n))
- def primef(num):
- if (num==1 or num==0):
- return False
- elif (num==2):
- return True
- else:
- c=1
- for i in range(2,num):
- if(num%i!=0):
- c+=1
- if(c==num-1):
- return True
- else:
- return False
- n=int(input("Enter Number to check Prime="))
- print(primef(n))
Screenshot of above Program with Output.
Prime Number |
Note:
- If you have any problem related to this program. Please do comment your Problem or Mail us.
- For illustrating the any concept you can comment by line number.
- Thank you! For more programs do regular visit to Coding 4 Programming.
- Get link
- X
- Other Apps
Labels:
Python
Popular Posts
To Check Prime Number | For Loop | Python
- Get link
- X
- Other Apps
To Check Perfect Number | Function | For Loop | Python
- Get link
- X
- Other Apps
Comments
Post a Comment