I'm very new to python, so this is very basic. I'm using the same basis i used on an add row program, which is probably why it comes up adding a row. When i read it back to myself, it seems to make sense. Thanks in advance for any help.
def add_column(matrix):
"""
>>> m = [[0, 0], [0, 0]]
>>> add_column(m)
[[0, 0, 0], [0, 0, 0]]
>>> n = [[3, 2], [5, 1], [4, 7]]
>>> add_column(n)
[[3, 2, 0], [5, 1, 0], [4, 7, 0]]
>>> n
[[3, 2], [5, 1], [4, 7]]
"""
rows=len(matrix)
columns=len(matrix[1])
new_matrix = []
for columns in range(rows):
new_matrix = matrix + [(1 * [0]) * rows]
return new_matrix
if __name__ == '__main__':
import doctest
doctest.testmod()
this is what comes up when i run it:
>>> ================================ RESTART ================================
>>>
**********************************************************************
File "__main__", line 4, in __main__.add_column
Failed example:
add_column(m)
Expected:
[[0, 0, 0], [0, 0, 0]]
Got:
[[0, 0], [0, 0], [0, 0]]
**********************************************************************
File "__main__", line 7, in __main__.add_column
Failed example:
add_column(n)
Expected:
[[3, 2, 0], [5, 1, 0], [4, 7, 0]]
Got:
[[3, 2], [5, 1], [4, 7], [0, 0, 0]]
**********************************************************************
1 items had failures:
2 of 5 in __main__.add_column
***Test Failed*** 2 failures.
>>> *******************************************