Okay, i've been working on this assignment for hours. I'm a total python newb but i've done pretty well so far. I'm stumped now though. I was hoping someone could point me in the right direction as to why i'm getting the error message below. The program is supposed to accept a list of denominations and a list of quantities and output a final value. We were never taught what that error message means so i'm not even sure where to start :/.

Any hints?

Evaluating a2.py
Traceback (most recent call last):
File "/Users/xavier/<string>", line 30, in <module>
File "/Users/xavier/<string>", line 21, in calcValue
TypeError: 'list' object is not callable

def calcValue (denom, quantities):
        newlist = list()
        i = 0
        i2 = 0
        while i < len(denom):
            x = denom(i) * quantities(i)
            i = i + 1
        while i2 < len(newlist):
            finalval = finalval + newlist(i2)
            i2 = i2 + 1
        return finalval

x = [10000, 5000]
y = [1, 1]

print calcValue(x,y)
9 Years
Discussion Span
Last Post by nxavier

Your error is most likely here:
finalval = finalval + newlist(i2)
you probably mean:
finalval = finalval + newlist[i2]
Also check the other list indexes. () would be a call, [] is used for indexed list element.

It also would help to be a bit more specific in your thread title.



I love you. I wasn't aware of the difference between () and [].

Thanks a lot! It's good to know it was a simple problem with the code and not something fundamental!

works great!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.