You can download this code by clicking the button below.
This code is now available for download.
Calculate the sum of natural numbers from 1 to n
Technology Stack : None
Code Type : Function
Code Difficulty :
def sum_naturals(n):
total, current = 0, 1
while current <= n:
total += current
current += 1
return total