Summation of Natural Numbers from 1 to n

  • Share this:

Code introduction


Calculates the sum of natural numbers from 1 to n


Technology Stack : None

Code Type : Mathematical calculation function

Code Difficulty :


                
                    
def sum_to_n(n):
    total = 0
    for i in range(1, n+1):
        total += i
    return total                
              
Tags: