跳到主要內容

[Python] While Loop for 9x9 Multiplication Table

  "Just Share and Record my learning track"

#While Loop to display 9 x 9 matrix 
# Example 1 with i, j variables
i = 1
j = 1
while i <= 9:
    while j <= 9:
        print(i * j, end = " ")
        j += 1
    i += 1
    j = 1
    print()


# Example 2 with x, y variables 
x=1
y=1
while x<=9:
 while y<=9:
  print(x*y, end=' ')
  y+=1
 x+=1
 y=1
  print() # Error IndentationError: unexpected indent
#Example 2 failed because of print() alignment problem




留言