I'm trying to print a square two-dimensional array of 0s. I don't understand why I keep getting a triangular shape with this code. Why is it that with each ROW I print, I print one less column?
def ar(i):
j = i
for i in range(i):
for j in range(j):
print('0', end=" ")
print()
range(5)will produce the values from 0 to 4 - one less then the inputted number.Your inner loop
joverwrites your localjand due to the nature ofrange()it will decrease by 1 for each outer loop.Fix:
You do not need named loop-vars, substitute with
_:Output: