or

ask mattrab Visit www.askmattrab.com for more academic resources.

Python program to check whether the given number is prime or not.

Pythonlogo

#To check whether the input number is prime or not try: #It runs if the input is an integer     a=int(input('Enter a natural number greater than 1'))     if a>1:         for b in range(2,a):             if(a%b)==0:                 print(a,'is not a prime number')                 break         else:             print(a, 'is a prime number')     else:         print('Please enter a valid number') except ValueError: #If the user is naughty and enters other than an integer     print('Please enter a valid number')