Python——利用循环语句打印九九乘法表
for循环实现
for i in range(1, 10):
for j in range(1, i + 1):
print("{} x {} = {:<2} ".format(j, i, i * j), end='')
print()
双层while循环实现
i = 1
while i < 10:
j = 1
while j <= i:
print("{} x {} = {:<2} ".format(j, i, i * j), end='')
j += 1
i += 1
print()
单层while循环实现
i = 1
j = 1
while i < 10:
if j <= i:
print("{} x {} = {:<2} ".format(i, j, i * j), end='')
j += 1
else:
i += 1
j += 1
print()
i = 0
j = 1
while j < 10:
i += 1
print("{} x {} = {:<2} ".format(i, j, i * j), end='')
if(i == j):
print()
i = 0
j += 1