# # Sep 16 homework # chap 3 exercise 12 # Jim Mahoney's example solution. # # Find the sum of the cubes of the first n natural numbers, # where n is supplied by the user. # print("-- chap3ex12.py --") print("Find the sum of the cubes of the first n integers.") def sum_cubes(): n = int(input("What is n? ")) total = 0 for i in range(1, n+1): # Note: 1,2,3,...,n ; NOT 0,1,...,n-1. total = total + i**3 # print(" DEBUG: i=", i, "; total =", total) print("The sum of 1**3 + ... +", n, "**3 is", total) sum_cubes()