Sum from 0 to n

EasyFunction Programs · 16 of 39

Write a Python function to calculate the sum of numbers from 0 to 10.

Advertisement
Output
55

Approach

  1. sum(range(n + 1)).

Solution

Python
def sum_to(n=10):    return sum(range(n + 1)) print(sum_to())
Output
55

Learn the concept

New to this topic? Read the lesson, then come back.

More function programs

← All 39 Function Programs

Leave a Comment