"Cherry_man1" (Cherry_man1)
08/26/2014 at 15:31 • Filed to: Coding, $kaybait | 0 | 14 |
Programmers of OPPO I need your help!
Help me figure this error
if its too small lemme know and I'll fix it.
Here is a GT40
KusabiSensei - Captain of the Toronto Maple Leafs
> Cherry_man1
08/26/2014 at 15:34 | 0 |
I don't think len in python takes square brackets to determine its parameter.
for row in range(len[matrix]):
should be (likely)
for row in range(len(matrix)):
#ImOnlyAComputerScientist
twochevrons
> Cherry_man1
08/26/2014 at 15:35 | 0 |
I'm not a python guru, but it looks as though the line "for row in range(len[matrix])" should be using round brackets, not square. The "not subscriptable" error is kind of cryptic, but sometimes the index into an array is called the subscript, if that helps clear things up.
KusabiSensei - Captain of the Toronto Maple Leafs
> twochevrons
08/26/2014 at 15:38 | 1 |
This is likely the issue, since the index is generally dereferenced in a base+offset fashion (indicated by square brackets).
I learned all this stuff on C, so doing pointer math and dereferencing with the -> operator, that was fun times...
#OhTheMemoriesLeak
Tohru
> Cherry_man1
08/26/2014 at 15:38 | 0 |
Looks like those should be parens - ( ) - not brackets - [ ].
Cherry_man1
> KusabiSensei - Captain of the Toronto Maple Leafs
08/26/2014 at 15:40 | 0 |
Tired your idea but its only giving out one columns addition and thats the last column
Cherry_man1
> Tohru
08/26/2014 at 15:41 | 0 |
where exactly?
twochevrons
> KusabiSensei - Captain of the Toronto Maple Leafs
08/26/2014 at 15:41 | 0 |
I'm much more a C kind of guy – at the college that I started at, computer science 101 jumped right in with C to begin with. Pointers came up within a few weeks, which was an ...interesting... experience. Still, I think that it did me well – having all the underlying concepts so exposed makes it easy to get a handle on what exactly is going on.
Tohru
> Cherry_man1
08/26/2014 at 15:44 | 0 |
For col in Range (len(m[0])).
Try replacing the brackets with parenthesis and see what happens.
Cherry_man1
> Tohru
08/26/2014 at 15:49 | 0 |
I got it to wrk
KusabiSensei - Captain of the Toronto Maple Leafs
> Cherry_man1
08/26/2014 at 15:52 | 0 |
This shows that your sumColumn function works, and the issue is now in your main function.
You could use the same method you use to print the array out, and only add to the total where the column index is what you pass it, otherwise it does a continue.
That would iterate over each matrix location matrix[i][j], and only add to total matrix[i][col] (You can either do a continue or add 0 otherwise)
for i in matrix
for j in i
if( j == col ? tot += matrix[i][j] : tot += 0)
EDIT: Python doesn't support the C inline if syntax, so you'll need to make it explicit like this:
if (j == col)
tot += matrix[i][j];
else
continue; //Or Python's equivalent. I think in C...
Tohru
> Cherry_man1
08/26/2014 at 15:53 | 2 |
Good man. Now leave no notes or comments on how you fixed it to screw the next person that looks at the code, like a true programmer.
KusabiSensei - Captain of the Toronto Maple Leafs
> twochevrons
08/26/2014 at 15:58 | 1 |
I was a CS at Georgia Tech not that long ago.
You'll note that almost all of my pseudocode is C syntax based. I even threw a conditional operator in, but my thought processes allow for function calls where as C makes you only use conditional operators on assignment statements (usually. Depends on how paranoid you have the syntax checker on your compiler set :) )
twochevrons
> KusabiSensei - Captain of the Toronto Maple Leafs
08/26/2014 at 16:09 | 0 |
I'm a CS student at the University of Minnesota at the moment, trying to finish my degree after a 3 year hiatus. It was interesting to see people's first reactions to C here – most people here don't really start to use it until a sophomore/junior-level course on OS basics – definitely a different experience to what I had.
Cherry_man1
> Tohru
08/26/2014 at 16:17 | 0 |
I didnt honestly its just our lab assignment