Hello, I am currently taking a programming course in Python and I am using Python 3 and I am having some trouble with my assignment. I have already gotten a comment on what I need to fix in my code for it to pass in my course’s grader but I don’t understand it so I was wondering if someone could explain it a little better and possibly show me how to fix it. I have posted the instructions for the assignment, my code, and a comment below. Can someone please help me comprehend what the comment means?
Using the following array, write a method to swap the image vertically.
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
def flipIt(array): for i in range(len(array)): length = len(array[i]) for j in range(length // 2): temp = array[i][j] array[i][j] = array[i][length - 1 - j] array[i][length - 1 - j] = temp #testing pic = [['@', ' ', ' ', ' ', ' ', '@'], ['@', '@', ' ', ' ', ' ', '@'], ['@', ' ', '@', ' ', ' ', '@'], ['@', ' ', ' ', '@', ' ', '@'], ['@', ' ', ' ', ' ', '@', '@'], ['@', ' ', ' ', ' ', ' ', '@']] flipIt(pic) for i in pic: for j in i: print(j,end=' ') print()
Your flipIt function needs to reverse the order of the arrays - yours reverses the order of the elements inside the arrays. This can be seen if you make what you’re flipping not symmetric - for example, if you set it to be just [[1,2],[3,4]], your code results in
2 1 4 3
when it should be
3 4 1 2
Instead of swapping elements inside of array[i], you should be swapping the elements directly in array.