I do not know how to start, I would like to know how to add a number to another in a range for example:
2 = 2
3 = 5
4 = 11
And so on I can not go on, if anyone can help me thank you right away.
I do not know how to start, I would like to know how to add a number to another in a range for example:
2 = 2
3 = 5
4 = 11
And so on I can not go on, if anyone can help me thank you right away.
You can use the function sum
the code would be this:
print(sum([1,2,3]))
separated by variables:
lista = [1,2,3]
soma = sum(lista)
print(soma)
If you understand your question, you want to add all elements of a range
use FOR next to range,
n_elementos = 5
soma = 0
for i in range(1,n_elementos+1):
soma += i
print(soma)
o 'n_elements + 1' is due to the range (x, y) go from x to y-1