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:
Notice that similar to slices of strings or lists, the range() also works with an inclusive start and an exclusive end.
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.