# [Tutor] calculate the sum of a variable - python

nookasree ponamala nookasree at yahoo.com
Mon Mar 7 08:27:28 CET 2011

```Thanks a lot Marc. This works now.

Sree.

--- On Mon, 3/7/11, Marc Tompkins <marc.tompkins at gmail.com> wrote:

From: Marc Tompkins <marc.tompkins at gmail.com>
Subject: Re: [Tutor] calculate the sum of a variable - python
To: "nookasree ponamala" <nookasree at yahoo.com>
Cc: "Wayne Werner" <waynejwerner at gmail.com>, tutor at python.org
Date: Monday, March 7, 2011, 10:54 AM

On Sun, Mar 6, 2011 at 8:46 PM, nookasree ponamala <nookasree at yahoo.com> 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110306/38cbce0b/attachment.html>
```