Summation of Natural Numbers from 1 to n

  • Share this:

Code introduction


Calculates the sum of natural numbers from 1 to n.


Technology Stack : Built-in functions sum and range

Code Type : Function

Code Difficulty :


                
                    
def sum_to_n(n):
    return sum(range(1, n+1))