When working with numbers, it’s sometimes very useful to work with sequences. In some applications, we might be interested in the sequence of numbers 0, 1, 2, ..., n. In another application, the important numbers might lie on a segment l, l + 1, l + 2, ..., r.
The range() command makes it easy to work with ranges of numbers. It can generate numbers in any range with any interval between each pair:
When used with other expressions, we can use range() without the list(). In the examples above, we have used list() so that the print statement displays a nice output.
Challenge
Given an integer n as an input, write a program that would output the sum of numbers 1, 2, ... n.