Prime Number Program in Python
Advertisements
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
Google Advertisment