Sum of Integers from 1 to n Calculation

  • Share this:

Code introduction


Compute the sum of all integers from 1 to n


Technology Stack : Built-in functions sum() and range()

Code Type : Mathematical calculation function

Code Difficulty :


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