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)`