Python Programming – John Zelle: Chapter 3 ex. 11

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

Chapter 3 Exercise 11

Python

1 2 3 4 5 6 7 8 9 10 11 12 13 | #Chapter 3 Exercise 11 # Write a program to find the sum 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 first natural numbers") natn = eval(input("How many natural numbers do you want to sum? ")) add = 0 for i in range (natn): add = add + i print(add) main() |

Run =

This program to calculates the sum of the first natural numbers

How many natural numbers do you want to sum? 5

10