dynamic names

V

Val Bykoski

I'm currently in a familiar to many business of filing my tax
return. Being a big fan of Python and to make the process less painful,
i started by writing my favored schedules A,B,C, and the most favored
form 1040 in Python. Everything was a real fun until i got to the
very famous motif "add lined Lx to Ly".
This is my naive (master)piece:

def sumL(L1,L2):
# sum up a range of Ls
tot=0.
for L in range(L1,L2+1):
#nL=exec("L%s" % L)
tot=tot + ("L%s" % L)
return tot

pythonw -u "sumL.py"
Traceback (most recent call last):
File "sumL.py", line 11, in ?
sumL(1,4)
File "sumL.py", line 7, in sumL
tot=tot + ("L%s" % L)
TypeError: unsupported operand type(s) for +: 'float' and 'str'
Exit code: 1

Any help would be life-saving.

let's-make-python-a-tax-pain-killer-ly y'rs
val
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top