[Tutor] calculate the sum of a variable - python
Marc Tompkins
marc.tompkins at gmail.com
Mon Mar 7 06:24:10 CET 2011
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/3a0b6a43/attachment.html>
More information about the Tutor
mailing list