python 3.x - How does this code work? What tells it to stop printing after the third row? Can someone break it down for me, in the most dumbed down way possible? -
import random def main(): printmatrix(3)
i don't understand how code stops after third row
def printmatrix(n): in range(1, n + 1): j in range(1, n + 1): print(random.randint(0, 1), end = " ") print() main()
range(1,n+1) builtin returns [1, 2, 3], iterating on range(1, n+1) same iterating on [1, 2, 3] - each loop body executes 3 times before terminating. inner 1 prints entries horizontally , outer 1 causes inner 1 execute 3 times.
Comments
Post a Comment