Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95803
| References | <2b0f07c4-cda8-4bf9-9ef3-b80cccec81a4@googlegroups.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2015-08-31 17:34 -0600 |
| Subject | Re: Hi am new to python |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.23.1441064117.23514.python-list@python.org> (permalink) |
On Mon, Aug 31, 2015 at 5:27 PM, Chubasco Diranga <alpharulz@gmail.com> wrote: > Can anyone please help me with the following please? > > My question is in a while loop; how do l sum all the numbers in the given list (list_a)? > > list_a = [8, 5, 2, 4] > sum_a = 0 # for storing the sum of list_a > i = 0 # for looping through the list_a# Use a while loop to sum all numbers in list_a# If you store the sums into sum_a > print(sum_a) # should print 19 You don't need a loop at all. Take a look at the builtin sum function: https://docs.python.org/3.4/library/functions.html#sum
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Hi am new to python Chubasco Diranga <alpharulz@gmail.com> - 2015-08-31 16:27 -0700 Re: Hi am new to python Ian Kelly <ian.g.kelly@gmail.com> - 2015-08-31 17:34 -0600 Re: Hi am new to python Emile van Sebille <emile@fenx.com> - 2015-08-31 16:36 -0700 Re: Hi am new to python Chris Angelico <rosuav@gmail.com> - 2015-09-01 10:01 +1000 Re: Hi am new to python Ben Finney <ben+python@benfinney.id.au> - 2015-09-01 10:22 +1000
csiph-web