I've written a small program to test whether a number is prime. But in the back of my mind, I feel it should be simpler and shorter. Can anyone advise. Thanks. from math import sqrt def prime(n): factor = 0 for i in range(2, sqrt(n) + 1): if n % i == 0: factor = factor + 1 break if factor == 0: print "Prime" else: print "Composite"