Hello, Thanks for pointing this out. I change it to this : def add_vectors(u, v): """ >>> add_vectors([1, 0], [1, 1]) [2, 1] >>> add_vectors([1, 2], [1, 4]) [2, 6] >>> add_vectors([1, 2, 1], [1, 4, 3]) [2, 6, 4] >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0]) [13, -4, 13, 5] """ teller=1 getal1=0 getal2=0 while teller < len(u): getal1 = getal1 + u[teller,0] + v[teller,0] getal2 = getal2 + v[teller,1] + v[teller,1] teller=teller+1 uitkomst2 = [getal1, getal2] return uitkomst2 uitkomst= [] vector= [[1,0], [1,1]] v=vector[0] u=vector[1] print u, v uitkomst = add_vectors(u,v) print uitkomst But now Im getting this message :
Traceback (most recent call last): File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 28, in <module> uitkomst = add_vectors(u,v) File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 17, in add_vectors getal1 = getal1 + u[teller,0] + v[teller,0]TypeError: list indices must be integers, not tuple Roelof Date: Fri, 27 Aug 2010 16:20:27 +0100 Subject: Re: [Tutor] exercise problem From: wpr...@gmail.com To: rwob...@hotmail.com CC: tutor@python.org Hi Roelof, See below On 27 August 2010 16:05, Roelof Wobben <rwob...@hotmail.com> wrote: uitkomst = add_vectors[u,v] But now I get this error message : Traceback (most recent call last):File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 27, in <module> uitkomst = add_vectors[u,v] TypeError: 'function' object is not subscriptable So it seems that I can't use vectors as a variable in a function. Carefully compare the syntax for calling your function (as in the doctest) to what you've written above. See the difference? (Hint: check the type of parentheses...) The error message is giving you a hint -- a subscriptable item is something like a list or array. They use square brackets. Function calls always use (round) parentheses. To python, it looks like you're trying to subcript the function object "add_vectors", which obviously isn't possible. Hence the message. Regards, Walter
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor