[Tutor] exercise problem

christopher.henk at allisontransmission.com christopher.henk at allisontransmission.com
Fri Aug 27 19:04:57 CEST 2010

Roelof Wobben wrote on 08/27/2010 12:18:01 PM:

> > Date: Fri, 27 Aug 2010 12:00:23 -0400
> > From: bgailer at gmail.com
> > To: rwobben at hotmail.com
> > CC: tutor at python.org
> > Subject: Re: [Tutor] exercise problem
> > 
> > I have been reading your posts and responses. I find myself frustrated 

> > with your lack of understanding of Python fundamentals and the time 
> > energy others are putting in that seems to help only a little.
> > 
> > I recommend you take a very basic tutorial, and be sure you understand 

> > the basic concepts before tackling what seems too hard for you
> I follow this basic tutorial : 
> > 
> > Also I encourage you to take each error message and look up the topic. 

> > In this case
> > 
> > getal1 = getal1 + u[teller,0] + v[teller,0]
> > TypeError: list indices must be integers, not tuple
> > 
> > What does this error tell you?
> That the list index must be a integer.
> > 
> > What is a tuple? What is an integer? Where is there a tuple in this 
> > expression? What are you trying to do?
> What a tuple is i can't tell you. it's in the next chapter.
> A integer is a number.
> What Im trying to do is that I want all the first numbers of the vectors 
are added and all the second numbers.
> So if I have this vector [1.0] [1,1]

You seem still confused on how your parameters to your function are 
working or the assignment in general.  You do not have a vector [[1,0] 
[1,1]] being passed into your function.  You are passing in two lists 
(vectors).  The first one 'u' is [1,0] , the second 'v' is [1,1] 
part of your code below:
vector= [[1,0], [1,1]]
print u, v
uitkomst = add_vectors(u,v)

if you just print u it will show [0,1]
if you just print v it will print [1,1]

thus your code:
getal1 = getal1 + u[teller,0] + v[teller,0]
getal2 = getal2 + v[teller,1] + v[teller,1]

is not doing what you thought it would.  (the syntax is wrong also).  I am 
guessing you are trying to index a 2D matrix with this.  Section 9.18 
would show you how to do that in python.  However there is no 2D matrix in 
your function, there are 2 vectors u and v.
So to add the vectors you loop over the index numbers (see 9.13) in your 
tutorial. in this loop add the value referenced by the index in each list 
to each other (section 9.2), and assign it to your new list at the same 
index value (9.8).  The one thing that would catch you on the assignment 
part, is that the list you are assigning to must have an element at that 
index (I didn't see the append function mentioned in your tutorial yet). 
Therefore you must initialize the list to which you are assigning to make 
sure it is the same length as the vectors you are adding (9.12 gives a 
method for this). 
Hopefully that will get you a bit closer to your answer.  I would suggest 
spending time in this section and make sure you understand what each line 
is doing, since these concepts are fundamentals in python programming. 
Use the interactive session in python to quickly see what each command 
does.  Python is great in that it will give you instant feedback.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100827/6be7f20c/attachment.html>

More information about the Tutor mailing list