Sum of first n natural numbers

# Sum of first n natural numbers

Nterms = int(input("Enter number of terms:"))

total = 0
for idx in range(1, Nterms+1,1):
total += idx

print("Sum of first",Nterms,"natural numbers = ", total)

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu