Python Programming – John Zelle: Chapter 3 ex. 12

Write a program to find the sum of the cubes of the first (n) natural numbers, where the value of (n) is provided by the user.

#Chapter 3 Exercise 12 # Write a program to find the sum of the cubes of the first (n) natural numbers, # where the value of (n) is provided by the user. def main(): print("This program to calculates the sum of the cubes of the first natural numbers") natn = eval(input("How many natural cubes numbers do you want to sum? ")) add = 0 for i in range (natn): add = add + i**3 print(add) main()

Run =

This program to calculates the sum of the cubes of the first natural numbers

How many natural cubes numbers do you want to sum? 7

441

## Recent Comments