Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.06; 'returned.': 0.07; 'function,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; "(i'm": 0.16; 'determines': 0.16; 'food:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hint:': 0.16; 'interpreter,': 0.16; 'is;': 0.16; 'script,': 0.16; 'wrote:': 0.18; 'result.': 0.19; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'indentation': 0.31; 'piece': 0.31; 'anyone': 0.31; 'figure': 0.32; 'know.': 0.32; 'thanks!': 0.32; 'run': 0.32; 'another': 0.32; 'could': 0.34; 'problem': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'list': 0.37; 'does': 0.39; 'sure': 0.39; 'matter': 0.61; 'total': 0.65; '20,': 0.68; '2015': 0.84; 'stock.': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=LYEys0w3iEW7zKPLo/nHQw7xIXNUJKKVVlL3wMv2/qE=; b=Un0Uj1IlNOT/LZPlXnk6WKpY8wbsJU9D6steO56oFu06du8kBKBR2k1Q+wBAjJFqb8 PQtdOmuISPS50mjZABRTyLM+2KWb3Hw8qU3ivovxCX7bDj1sAv3fNzzoFgHgOvcmg5Ul OrF+epsmVqWsrxwiIvVo6VhHOzXUKOPcnFAgQszYyHXQyong0/xfFNUffRwNltDPV9D+ cExxJqX/A8TaH0mp/7IfmxkJQo6w4wxUSaKzTn2eySsKJlfI84UP4G32sY0Ch3016CLG pIEQ5edLjygCznGqvizmulmBsC8DuDhmsIp1uSYlFo3e2KgkB+lCfga3NSSkkr5PkjSB 1EYA== MIME-Version: 1.0 X-Received: by 10.224.43.202 with SMTP id x10mr52327478qae.16.1421713297810; Mon, 19 Jan 2015 16:21:37 -0800 (PST) In-Reply-To: References: Date: Tue, 20 Jan 2015 11:21:37 +1100 Subject: Re: Concerning Dictionaries and += in Python 2.x From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421713307 news.xs4all.nl 2858 [2001:888:2000:d::a6]:49590 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84037 On Tue, Jan 20, 2015 at 11:12 AM, Luke Tomaneng wr= ote: > def compute_bill(food): > total =3D 0 > for item in food: > if stock[item] > 0: > total +=3D prices[item] > stock[item] =3D stock[item] - 1 > return total > Whenever I run this script, "4" is returned. It does not seem to matter w= hat in in the list the script is run on. I have tried this on the Codecadem= y interpreter/emulator (I'm not sure which they use) and the repl.it interp= reter, 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