# file: InClassAssignment2.py # Here are the definitions for the following two functions presented: # sumN(n) returns the sum of the first n natural numbers if n is a positive integer, # and -1 otherwise # sumNSquares(n) returns the sum of squares of the first n natural numbers if n is a positive integer, # and -1 otherwise # # Program has main function that tests functions sumN(n) and sumNSquares(n) # def sumN(n): # put the code for this function here def sumNSquares(n): # put the code for this function here def main(): print("Testing sumN(n) and sumNSquares(n).") # Test 1 print("sumN(n) on n = -7: ", end='') if (sumN(-7) == -1): print("passed") else: print("failed") # Test 2 print("sumNSquares(n) on n = -7: ", end='') if (sumNSquares(-7) == -1): print("passed") else: print("failed") # Test 3 print("sumN(n) on n = 1: ", end='') if (sumN(1) == 1): print("passed") else: print("failed") # Test 4 print("sumNSquares(n) on n = 1: ", end='') if (sumNSquares(1) == 1): print("passed") else: print("failed") # Test 5 print("sumN(n) on n = 2: ", end='') if (sumN(2) == 3): print("passed") else: print("failed") # Test 6 print("sumNSquares(n) on n = 2: ", end='') if (sumNSquares(2) == 5): print("passed") else: print("failed") # Test 7 print("sumN(n) on n = 10: ", end='') if (sumN(10) == 55): print("passed") else: print("failed") # Test 8 print("sumNSquares(n) on n = 4: ", end='') if (sumNSquares(4) == 30): print("passed") else: print("failed") main()