Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #84037
| References | <bc9e302a-356c-4223-9c25-6a8003db48e6@googlegroups.com> |
|---|---|
| Date | 2015-01-20 11:21 +1100 |
| Subject | Re: Concerning Dictionaries and += in Python 2.x |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17869.1421713307.18130.python-list@python.org> (permalink) |
On Tue, Jan 20, 2015 at 11:12 AM, Luke Tomaneng <luketomaneng@gmail.com> wrote: > def compute_bill(food): > total = 0 > for item in food: > if stock[item] > 0: > total += prices[item] > stock[item] = stock[item] - 1 > return total > Whenever I run this script, "4" is returned. It does not seem to matter what in in the list the script is run on. I have tried this on the Codecademy interpreter/emulator (I'm not sure which they use) and the repl.it interpreter, but for the same result. If anyone could find the glitch in my code, please let me know. Thanks! > In Python, indentation determines block structure. Have another look at this function, and see if you can figure out where the problem is; hint: try printing something out every time you claim a piece of stock. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Concerning Dictionaries and += in Python 2.x Luke Tomaneng <luketomaneng@gmail.com> - 2015-01-19 16:12 -0800
Re: Concerning Dictionaries and += in Python 2.x Chris Angelico <rosuav@gmail.com> - 2015-01-20 11:21 +1100
Re: Concerning Dictionaries and += in Python 2.x Luke Tomaneng <luketomaneng@gmail.com> - 2015-01-19 16:31 -0800
Re: Concerning Dictionaries and += in Python 2.x MRAB <python@mrabarnett.plus.com> - 2015-01-20 00:27 +0000
Re: Concerning Dictionaries and += in Python 2.x Luke Tomaneng <luketomaneng@gmail.com> - 2015-01-19 16:34 -0800
Re: Concerning Dictionaries and += in Python 2.x Chris Angelico <rosuav@gmail.com> - 2015-01-20 11:46 +1100
Re: Concerning Dictionaries and += in Python 2.x Dan Stromberg <drsalists@gmail.com> - 2015-01-19 16:54 -0800
Re: Concerning Dictionaries and += in Python 2.x Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-21 05:01 +0000
Re: Concerning Dictionaries and += in Python 2.x Peter Otten <__peter__@web.de> - 2015-01-21 09:43 +0100
Re: Concerning Dictionaries and += in Python 2.x Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-21 14:10 +0000
Re: Concerning Dictionaries and += in Python 2.x Peter Otten <__peter__@web.de> - 2015-01-21 09:59 +0100
csiph-web