text: import sys def isInteger(x): """Checks if argument can be made to represent an int Returns 1 if so, 0 otherwise""" try: int(x) return 1 except: return 0 def isPrime(x): """Checks if argument is a prime number Returns 1 if so, 0 otherwise""" if x <= 1: return 0 else: for i in range(2, x / 2): if x % i == 0: return 0 return 1 def readInt(prompt = 'Enter an integer:'): """Read in and return an integer from standard input, printing prompt first and checking for valid input""" print prompt, while 1: x = sys.stdin.readline() if isInteger(x): return int(x) else: print 'That is not an integer, please try again:', if __name__ == '__main__': while 1: x = readInt('Enter a prime number:') if isPrime(x): for i in range(0, x): print i, sys.exit(0) else: print x, ' isn\'t a prime number.' Kojo Duncan wrote: > I. > > > > > >