# This program finds the sum of squares of first n postive integers, # where n is inputed by the user. def main(): print "This program finds the sum of squares of first n postive integers,", print "where n is inputed by the user." number=raw_input("Please input any positive integer and press Enter:") answer=sumOfSquares(number) print "The sum of squares of first",number,"positive integers is",answer # Finds the sum of squares of first n postive integers # raises Errors if the n value is not a positive integer # otherwise, returns the sum def sumOfSquares(n): if not n.isdigit(): raise TypeError('sumOfSquares(n): n must be an integer value') n=int(n) if n < 1: raise ValueError('sumOfSquares(n): n must be positive') sq = 0 for k in range(n+1): sq += k*k return sq main()