1.while语句中嵌套while语句:
i=1
while i<10:
j=1
while j<=i:
print("%d*%d=%-3d"%(i,j,i*j),end=" ")
j=j+1
i=i+1
print(end="\n")
2.while语句中嵌套for语句:
i=1
while i<10:
for j in range(1,i+1):
print("%d*%d=%-3d" % (i, j, i * j), end=" ")
i=i+1
print(end="\n")
3.for语句中嵌套while语句:
for i in range(1,10):
j=1
while j<=i:
print("%d*%d=%-3d" % (i, j, i * j), end=" ")
j=j+1
print(end="\n")
4.for语句中嵌套for语句:
for i in range(1,10):
for j in range(1,i+1):
print("%d*%d=%-3d" % (i, j, i * j), end=" ")
print(end="\n")
以上四种方法的运行结果都如下:
标签:语句,%-,end,Python,嵌套,while,print From: https://blog.51cto.com/u_15765782/5780690