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

Python

1 2 3 4 5 6 7 8 9 10 11 12 13 | #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