Thanks a lot Marc. This works now. Sree. --- On Mon, 3/7/11, Marc Tompkins <[email protected]> wrote:
From: Marc Tompkins <[email protected]> Subject: Re: [Tutor] calculate the sum of a variable - python To: "nookasree ponamala" <[email protected]> Cc: "Wayne Werner" <[email protected]>, [email protected] Date: Monday, March 7, 2011, 10:54 AM On Sun, Mar 6, 2011 at 8:46 PM, nookasree ponamala <[email protected]> wrote: Thanks for the reply Wayne, but still it is not working, when I used int It throws the below error: File "<stdin>", line 2, in <module> File "<stdin>", line 3, in summary File "<stdin>", line 3, in <genexpr> ValueError: invalid literal for int() with base 10: "'" I tried using float and the error is: Traceback (most recent call last): File "<stdin>", line 2, in <module> File "<stdin>", line 3, in summary File "<stdin>", line 3, in <genexpr> ValueError: invalid literal for float(): ' Thanks, Sree. I played with it a bit and simplified things a (little) bit: b = (aline[3].strip('$')) t = (a, float(b)) tot.append(t) print tot You were converting the tuple to a string before adding it to the list; you don't need to do that, and it was concealing the real cause of your problem, which is that you either need to skip/get rid of the top line of your file, or write some error-handling code to deal with it. Currently, you're trying to convert the string 'amt' into a number, and you just can't do that.
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
