AyanUpadhaya

Check Prime Number

May 20th, 2021 (edited)
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. #Python Program to Find Prime Number using For Loop
  2. #Any natural number that is not divisible by any other number except 1 and itself
  3. #called Prime Number.
  4.  
  5. user_num=int(input("Enter a number:"))
  6.  
  7. def is_prime(num):
  8.  
  9.     count=0
  10.  
  11.     for i in range(2,(num//2+1)):
  12.         if num%i==0:
  13.             count+=1
  14.             break
  15.     if count==0 and num!=1:
  16.         print(f"{num} is a prime number")
  17.     else:
  18.         print(f"{num} is not a prime number")
  19.  
  20. is_prime(user_num)
  21.        
  22.  
Add Comment
Please, Sign In to add comment