I am trying to create a function that does what the title is asking for. Without the use of any functions besides: range, len or append. The function would take the dimensional input of the 2D array, as well as the scaling factor, and then return a two-dimensional array multiplication table scaled by the scaling factor.
I have tried various different code but have left them out because they return 0 progress on test cases.
CodePudding user response:
If you want the output as a 2d array, you can use this:
def MatrixTable(width, height, scaling_factor):
return [[w*h*scaling_factor for w in range(1, width 1)] for h in range(1, height 1)]
MatrixTable(5, 3, 1)
Outputs:
[[1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15]]