Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'float': 0.05; 'modify': 0.05; 'assign': 0.07; 'defines': 0.07; 'omit': 0.07; 'python': 0.09; '0),': 0.09; 'beyond.': 0.09; 'compute': 0.09; 'python:': 0.09; 'subject:problems': 0.09; 'index': 0.13; 'elements,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:these': 0.16; 'wrote:': 0.17; 'have:': 0.17; 'refers': 0.17; 'variables': 0.17; 'variable': 0.20; 'defined': 0.22; 'elements': 0.23; 'statement': 0.23; 'this:': 0.23; 'tried': 0.25; 'least': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'question': 0.27; 'besides': 0.27; 'i.e.': 0.27; 'initial': 0.28; 'included': 0.29; "i'm": 0.29; '(and': 0.32; 'received:84': 0.32; 'says': 0.33; 'to:addr:python-list': 0.33; 'equal': 0.33; 'list': 0.35; 'data,': 0.35; 'doing': 0.35; 'list.': 0.35; 'add': 0.36; 'but': 0.36; "didn't": 0.36; 'subject:with': 0.36; 'two': 0.37; 'uses': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'called': 0.39; 'list,': 0.39; 'received:192.168': 0.40; 'end': 0.40; 'most': 0.61; 'skip:n 10': 0.63; 'to,': 0.65; 'total': 0.65; 'sum': 0.66; 'header:Reply-To:1': 0.68; 'ranges': 0.71; 'reply-to:no real name:2**0': 0.72; 'counts': 0.81; 'reply-to:addr:python.org': 0.84; 'temperature': 0.84; 'temps': 0.91; 'total,': 0.91; 'average': 0.93 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=HO4d4PRv c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=Tv4_tr9OjFAA:10 a=LiaZj268PPwA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=2NWuDE5rlK8A:10 a=zA3STrf1AAAA:8 a=6RHqquy23lzxuAAa4cYA:9 a=wPNLvfGTeEIA:10 a=d035lmYt8NkOAtI4:21 a=bjQE5cqm6p8YPnXj:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Wed, 30 Jan 2013 03:59:32 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: struggling with these problems References: <72be91aa-b9fc-4225-bd54-0ae3459acea3@googlegroups.com> In-Reply-To: <72be91aa-b9fc-4225-bd54-0ae3459acea3@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359518372 news.xs4all.nl 6951 [2001:888:2000:d::a6]:39051 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37917 On 2013-01-30 03:26, su29090 wrote: > 1.Given that worst_offenders has been defined as a list with at least 6 elements, write a statement that defines lesser_offenders to be a new list that contains all the elements from index 5 of worst_offenders and beyond. Do not modify worst_offenders . > > I tried this but it didn't work: > > lesser_offenders = worst_offenders[5:6] > Python uses half-open ranges (and counts from 0), which means that the start index is included and the end index is excluded. Therefore, worst_offenders[5:6] means the slice from index 5 up to, but excluding, index 6; in other words, an empty list. The question says "and beyond"; in Python you can just omit the end index to indicate everything up to the end. > 2.Given a variable temps that refers to a list, all of whose elements refer to values of type float , representing temperature data, compute the average temperature and assign it to a variable named avg_temp . Besides temps and avg_temp , you may use two other variables -- k and total . > > > I'm not sure about this one but this is what I have: > > for k in range(len(temps)): > total += temps[k] > > avg_temp = total / len(temps) > You didn't set the initial value of total, which is 0. > 3.Associate the sum of the non-negative values in the list numbers with the variable sum . > > is it this: > > for numbers in sum: > if sum +=? > > I'm confused at #3 the most > Well, that's not valid Python. What you want to do is to add each number from the list to the sum only if it's non-negative, i.e. greater than or equal to 0. > i'm not doing it in python 3.2.3 it's called Myprogramminglab. > Have a look at Dive Into Python: http://www.diveintopython.net/