# Where do I call my printArray function in this assignment?

I am currently taking a computer science course called Intro to Computer Science and I am learning how to code in Python (Python 3) and I am having trouble with an assignment. We are learning about 2D arrays and this assignment goes over that. I have written some code for the assignment already but an instructor commented on my code and said I was missing something. What I want to know is: How do I call printArray at the correct indentation as the instructor says? I have already tried what the instructor said (I show this at the bottom) and the code is still not passing the grader so I assumed that I interpreted something in the comment the wrong way.

Here are the assignment instructions:

Here is my code: (The two lines I have commented out are the lines that the instructor wanted me to change)

``````def printArray(N):
for r in N:
for c in r:
print(c,end = " ")
print()
print()

def flipHorizontal(N):
Array = []
for i in range(0,len(N)):
pos = []
for j in range(0,len(N[0])):
pos.append(N[i][len(N[0])-j-1])
Array.append(pos)
#printArray(Array)
return Array

def flipVertical(N):
newArray = []
for i in range(0,len(N)):
newArray.append(N[len(N)-i-1])
#printArray(newArray)
return newArray

Array1 = [[0, 2, 0, 0,0], [0, 2, 0, 0,0], [0, 2, 2, 0,0], [0, 2, 0, 2,0],[0, 2, 0, 0,2]]
printArray(Array1)
flipedHor = flipHorizontal(Array1)
printArray(flipedHor)
``````

Here is the comment:

Here is the code that I thought would work after I read the comment:

```````def printArray(N):`
`    for r in N:`
`        for c in r:`
`            print(c,end = " ")`
`        print()`
`    print()`

`def flipHorizontal(N):`
`    Array = []`
`    for i in range(0,len(N)):`
`        pos = []`
`        for j in range(0,len(N[0])):`
`            pos.append(N[i][len(N[0])-j-1])`
`        Array.append(pos)`
`    return Array`
`    printArray(Array)`

`def flipVertical(N):`
`    newArray = []`
`    for i in range(0,len(N)):`
`        newArray.append(N[len(N)-i-1])`
`    return newArray`
`    printArray(newArray)`

`Array1 = [[0, 2, 0, 0,0], [0, 2, 0, 0,0], [0, 2, 2, 0,0], [0, 2, 0, 2,0],[0, 2, 0, 0,2]]`
`printArray(Array1)`
`flipedHor = flipHorizontal(Array1)`
`printArray(flipedHor)`
`flipedVer=flipVertical(Array1)`
`printArray(flipedVer)`
``````

Your first version output this: (with `printArray(Array)` no more in a comment)

``````0 2 0 0 0
0 2 0 0 0
0 2 2 0 0
0 2 0 2 0
0 2 0 0 2

0 0 0 2 0

0 0 0 2 0
0 0 0 2 0

0 0 0 2 0
0 0 0 2 0
0 0 2 2 0

0 0 0 2 0
0 0 0 2 0
0 0 2 2 0
0 2 0 2 0

0 0 0 2 0
0 0 0 2 0
0 0 2 2 0
0 2 0 2 0
2 0 0 2 0

0 0 0 2 0
0 0 0 2 0
0 0 2 2 0
0 2 0 2 0
2 0 0 2 0
``````

As you can see it is not what you want to get.

I can’t run the second version of your code as there are backticks on each line, and that make it impossible to copy.

To see what your code output, you can run it on something like repl.it
As a debugging tool, if you have difficulties in seeing what happens at each step, you can also use pythontutor.com

If you post your second version of the code with no backticks at each line, I may try to hint what’s wrong.

remember also that it is the `flipHorizontal` function that should call the `printArray` function
you shouldn’t have this line

also, you never call `flipVertical`

Here is the second version of my code.

``````def printArray(N):
for r in N:
for c in r:
print(c,end = " ")
print()
print()

def flipHorizontal(N):
Array = []
for i in range(0,len(N)):
pos = []
for j in range(0,len(N[0])):
pos.append(N[i][len(N[0])-j-1])
Array.append(pos)
return Array
printArray(Array)

def flipVertical(N):
newArray = []
for i in range(0,len(N)):
newArray.append(N[len(N)-i-1])
return newArray
printArray(newArray)

Array1 = [[0, 2, 0, 0,0], [0, 2, 0, 0,0], [0, 2, 2, 0,0], [0, 2, 0, 2,0],[0, 2, 0, 0,2]]
printArray(Array1)
flipedHor = flipHorizontal(Array1)
printArray(flipedHor)
flipedVer=flipVertical(Array1)
printArray(flipedVer)
``````

remove the last and second to last `printArray` calls: by requirements you should have at the bottom only one `printArray` call as the `printArray` function should instead be called inside the other two functions

have you tried running your code?
what’s the output?
is it what you should get?

By last and second to last printArray calls, do you mean these (the ones that I commented out:)

``````def printArray(N):
for r in N:
for c in r:
print(c,end = " ")
print()
print()

def flipHorizontal(N):
Array = []
for i in range(0,len(N)):
pos = []
for j in range(0,len(N[0])):
pos.append(N[i][len(N[0])-j-1])
Array.append(pos)
return Array
printArray(Array)

def flipVertical(N):
newArray = []
for i in range(0,len(N)):
newArray.append(N[len(N)-i-1])
return newArray
printArray(newArray)

Array1 = [[0, 2, 0, 0,0], [0, 2, 0, 0,0], [0, 2, 2, 0,0], [0, 2, 0, 2,0],[0, 2, 0, 0,2]]
printArray(Array1)
flipedHor = flipHorizontal(Array1)
#printArray(flipedHor)
flipedVer=flipVertical(Array1)
#printArray(flipedVer)
``````

Can you show me what you mean by only having one printArray call at the bottom and where it should be inside the other two functions?

`printArray`
`flipHorizontal`
`flipVertical`
and if they are well written, the two flip functions will have a call to `printArray` inside them, which is the part you are struggling with