Prime Number Program in Python


Prev Tutorial Next Tutorial

Print Prime Number Program in Python

Prime number is only divisible by 1 and number it self. So for this type of program you need to check number is divisible by other number or not. If number is divisible by others number it means number is not prime number.

Prime Number Program in Python

# Receive input from the user
num = int(input("Enter a number: "))

# prime numbers are greater than 1
if num > 1:
   # check for factors
   for i in range(2,num):
       if (num % i) == 0:
           print(num,"is not a prime number")
           print(i,"times",num//i,"is",num)
           break
   else:
       print(num,"is a prime number")
       
# if input number is less than
# or equal to 1, it is not prime
else:
   print(num,"is not a prime number")

Output

	
Enter a number: 407
407 is not a prime number
11 times 37 is 407

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements