Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.052 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'subject:file': 0.07; 'cc:addr:python-list': 0.11; 'def': 0.12; 'line.split()': 0.16; 'index': 0.16; 'wrote:': 0.18; '3.0': 0.19; 'starts': 0.20; 'feb': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; '>': 0.26; '2.0': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'url:mailman': 0.30; 'lines': 0.31; 'subject:numbers': 0.31; 'says': 0.33; 'url:python': 0.33; 'table': 0.34; 'subject:from': 0.34; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'list': 0.37; 'skip:o 20': 0.38; 'pm,': 0.38; 'url:mail': 0.40; 'range': 0.61; 'name': 0.63; 'subject:The': 0.64; 'to:addr:gmail.com': 0.65; 'here': 0.66; '20,': 0.68; '11.': 0.74; 'scores': 0.91 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:to :cc:content-type; bh=XEZdPLluxCMAQiAgFZBw4mg9OuISU0sj8t9LjdTJLVM=; b=OOlXitVqSqBQqhLefi6KLMO/tRkseh23dE9dzAAfuqx/Jj/YLsgizxw5lTsdkCWn7L YE0GUteqf7nYVgOLsVFhgboUrDrgLxLwsKkET+zz3+Jj6xYvwajKI/r4vGLNxvQPIBUB 6+UNQmCHcO9DRWfxtNe7wLQtrNisSeQjlatAdupjsNff8aRzyzb169bHF670nnvRdSBv fk506M6sTHYpcLeDUELmp+o4wdQofprSRzv1shw8WqEByRbJs/3tROG8R9UUiuPhrNd3 XV8vUOgi3JIBJ6M55t872kLw9G8vuY9Uc+ylmGJozDBLdwoOsI+h4BiMLUkEHGHET+Ww uJgg== MIME-Version: 1.0 X-Received: by 10.52.183.106 with SMTP id el10mr1540309vdc.73.1392921169514; Thu, 20 Feb 2014 10:32:49 -0800 (PST) In-Reply-To: <9036049f-7d08-4de7-83f8-61e5fa2c2d2f@googlegroups.com> References: <882091da-a499-477e-8f50-c5bdde7cdfec@googlegroups.com> <9036049f-7d08-4de7-83f8-61e5fa2c2d2f@googlegroups.com> Date: Thu, 20 Feb 2014 13:32:49 -0500 Subject: Re: The sum of numbers in a line from a file From: Joel Goldstick To: kjakupak@gmail.com Content-Type: multipart/alternative; boundary=bcaec547cb9782581b04f2dabbdd Cc: python-list@python.org 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392921172 news.xs4all.nl 2973 [2001:888:2000:d::a6]:57323 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66779 --bcaec547cb9782581b04f2dabbdd Content-Type: text/plain; charset=UTF-8 On Feb 20, 2014 1:20 PM, wrote: > > What I've got is > def stu_scores(): > lines = [] > with open("file.txt") as f: > lines.extend(f.readlines()) > return ("".join(lines[11:])) > > scores = stu_scores() > for line in scores: > fields = line.split() > name = fields[0] Print fields here to see what's up > sum1 = int(fields[4]) + int(fields[5]) + int(fields[6]) > sum2 = int(fields[7]) + int(fields[8]) > average1 = sum1 / 3.0 > average2 = sum2 / 2.0 > print ("%s %f %f %") (name, average1, average2) > > It says that the list index is out of range on the sum1 line. I need stu_scores because the table from above starts on line 11. > -- > https://mail.python.org/mailman/listinfo/python-list --bcaec547cb9782581b04f2dabbdd Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Feb 20, 2014 1:20 PM, <kjakupak= @gmail.com> wrote:
>
> What I've got is
> def stu_scores():
> =C2=A0 =C2=A0 lines =3D []
> =C2=A0 =C2=A0 with open("file.txt") as f:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 lines.extend(f.readlines())
> =C2=A0 =C2=A0 return ("".join(lines[11:]))
>
> scores =3D stu_scores()
> for line in scores:
> =C2=A0 =C2=A0 fields =3D line.split()
> =C2=A0 =C2=A0 name =3D fields[0]
Print fields here to see what's up
> =C2=A0 =C2=A0 sum1 =3D int(fields[4]) + int(fields[5]) + int(fields[6]= )
> =C2=A0 =C2=A0 sum2 =3D int(fields[7]) + int(fields[8])
> =C2=A0 =C2=A0 average1 =3D sum1 / 3.0
> =C2=A0 =C2=A0 average2 =3D sum2 / 2.0
> =C2=A0 =C2=A0 print ("%s %f %f %") (name, average1, average2= )
>
> It says that the list index is out of range on the sum1 line. I need s= tu_scores because the table from above starts on line 11.
> --
> https= ://mail.python.org/mailman/listinfo/python-list

--bcaec547cb9782581b04f2dabbdd--