(Jun-09-2022, 03:05 PM)deanhystad Wrote: From your example, result = 100 - 20 - 4 - 10
This could also be represented as result = 100 - (20 + 4 + 10)
In both cases the first value is treated one way, and all subsequent values are treated in a different way.
Here's a start:
def subtractElements(listNums): result = ??? print("The result is", result subtractElements([100, 20, 4, 10])
I hope I'm not contravening any kind of protocol with this post; please tell me if I am so that I don't make the same mistake again.
That aside, I've come up with this as a solution.
def subtractElements(listNums): result = listNums[0] for number in range(1, len(listNums)): result -= listNums[number] print(result) subtractElements([100, 20, 4, 10])... but having done that, I read this: https://python-forum.io/thread-362.html
So, how to apply what is being said in that 'common pitfalls and what to do' to what I've done?
I ask simply because I want to improve my Python skills.
With thanks.
buran write Jun-14-2022, 05:37 AM:
Please, don't provide complete solution, even a poor one, to no effort questions. That's even more important in Homework section
Please, don't provide complete solution, even a poor one, to no effort questions. That's even more important in Homework section
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein