2
I am making a calculator and would like to subtract several elements from a list, this because the list can have as many elements as the user wants. See my code:
lista = [10, 5]
subt = lista[0]
for a in lista:
subt -= a
But the algorithm is giving me -5 as an answer, which should be 5 (10-5 = 5). It is worth mentioning again that the list can have as many elements as the user wants, be 2, 3, 4, 5, 100...
What a possible solution?
for a list like this 2, 3, 4, 5, 100 what you expect as a result ??
– ederwander
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site
– Maniero