how to print the sum of a range of numbers in python code example
Example 1: how to use sum with range python
res = sum(x for x in range(100, 2001) if x % 3 == 0)
Example 2: Sum All Numbers in a Range
const sumAll = arr => {
let maxNumber = Math.max(...arr)
let minNumber = Math.min(...arr)
let numbersArray = []
for(let i = minNumber; i <= maxNumber; i++){
numbersArray.push(i)
}
return numbersArray.reduce((acc, cur) => acc + cur, 0)
}
sumAll([1, 4]);