Checking for Prime number in Python

 Test Case:




case=1:

input=5

output=IsPrime

case=2:

Input=10

output=NotaPrime



Code:

num=int(input())

if num>1:

    for i in range(2,int(num/2)+1):

        if(num%i)==0:

            print(num,"NotaPrime")

            break

    else:

        print(num,"IsPrime")

else:

    print(num,"NotaPrime")

Output:

5

5 IsPrime


Try it Yourself ( our new feature )

Click on the "Try it Yourself" button to see how it works.


Blog

Post a Comment

Previous Post Next Post