The sum of ten numbers inserted from the user
Ben Bacarisse
ben.usenet at bsb.me.uk
Thu Feb 7 18:56:45 EST 2019
Grant Edwards <grant.b.edwards at gmail.com> writes:
> On 2019-02-07, Ben Bacarisse <ben.usenet at bsb.me.uk> 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
>>> notation!
>>>
>>> numbers=[]
>>>
>>> while len(numbers) < 10:
>>> try:
>>> chip = int(input('please enter an integer: '))
>>> except ValueError:
>>> print('that is not a number, try again')
>>> else:
>>> numbers.append(chip)
>>>
>>> print(sum(numbers))
>>
>> 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
>> requirement...
>
> Because you think it likely that tomorrow the marketing people are
> going to say "oh, and we want to know the min, max, mode, median,
> standard deviation, and count of odd vs. even.
>
> OTOH, they may instead say, "Oh, it's not 10 numbers, it's 10 million
> numbers."
Sure. I can think of reasons for all sorts of designs. Has there been
any hint? It looks like a beginners' exercise with little extra to go
on.
--
Ben.
More information about the Python-list
mailing list