The sum of ten numbers inserted from the user
Bart <bc at freeuk.com> writes:
> On 07/02/2019 20:45, Ben Bacarisse wrote:
>> Ian Clark <ianhclark510 at gmail.com> writes:
>>> This is my whack at it, I can't wait to hear about it being the wrong big o
>>> while len(numbers) < 10:
>>> chip = int(input('please enter an integer: '))
>>> except ValueError:
>>> print('that is not a number, try again')
>> Why would you not keep a running total, rather than list of the numbers?
>> I've not been following assiduously, so maybe I missed some other
> Because it separates the two tasks: (A) capture N values; (B) perform
> some operation on those values, in this case summing (and taking
> advantage here of the built-in sum()).
Sure. Did I miss some hint that this program might need to be more
flexible like that? It looks like a beginners' exercise.
If the purpose is to be flexible, why is an array the right option rather
than, say, accumulating a value over an iterable? You need some idea of
the future direction or what the exercise is intended to reinforce.