# Programmer: Sriram Pemmaraju # Date: Jan 30th, 2012 # This program reads a positive integer, greater than 1 and # determines whether this integer is a prime or not. # Version 4 import math n = int(raw_input("Please type a positive integer, greater than 1: ")) factor = 2 # initial value of possible factor isPrime = True # variable to remember if n is a prime or not factorUpperBound = math.sqrt(n) # the largest possible factor we need to test is sqrt(n) # loop to generate and test all possible factors while (factor <= factorUpperBound) and (isPrime): # test if n is evenly divisible by factor if (n % factor == 0): isPrime = False factor = factor + 1 # Output if isPrime: print n, " is a prime." else: print n, " is a composite."