Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95802 > unrolled thread
| Started by | Chubasco Diranga <alpharulz@gmail.com> |
|---|---|
| First post | 2015-08-31 16:27 -0700 |
| Last post | 2015-09-01 10:22 +1000 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | Chubasco Diranga <alpharulz@gmail.com> |
|---|---|
| Date | 2015-08-31 16:27 -0700 |
| Subject | Hi am new to python |
| Message-ID | <2b0f07c4-cda8-4bf9-9ef3-b80cccec81a4@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-08-31 17:34 -0600 |
| Message-ID | <mailman.23.1441064117.23514.python-list@python.org> |
| In reply to | #95802 |
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
[toc] | [prev] | [next] | [standalone]
| From | Emile van Sebille <emile@fenx.com> |
|---|---|
| Date | 2015-08-31 16:36 -0700 |
| Message-ID | <mailman.24.1441064314.23514.python-list@python.org> |
| In reply to | #95802 |
On 8/31/2015 4:27 PM, Chubasco Diranga 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 should familiarize yourself with the language -- there's a really easy answer to this. Review the tutorial at https://docs.python.org/3/tutorial/ Emile
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-09-01 10:01 +1000 |
| Message-ID | <mailman.25.1441065717.23514.python-list@python.org> |
| In reply to | #95802 |
On Tue, Sep 1, 2015 at 9:27 AM, 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 This is not a "do my homework for me" list. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2015-09-01 10:22 +1000 |
| Message-ID | <mailman.26.1441066967.23514.python-list@python.org> |
| In reply to | #95802 |
Chubasco Diranga <alpharulz@gmail.com> writes: > Can anyone please help me with the following please? Welcome! Is this a homework assignment? It's okay to ask for help with those, but we're not going to do the work for you. > My question is in a while loop; how do l sum all the numbers in the > given list (list_a)? There is a built-in function to do that. Have you completed the Python tutorial <URL:https://docs.python.org/3/tutorial/>? You may also want to participate in the ‘tutor’ forum for Python <URL:https://mail.python.org/mailman/listinfo/tutor> which is specialised to help beginners in Python. -- \ “Reichel's Law: A body on vacation tends to remain on vacation | `\ unless acted upon by an outside force.” —Carol Reichel | _o__) | Ben Finney
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web