标签:bsp 乘法 end nbsp -- += 乘法表 for 位置
#whlie循环
#方向一(左下角)
i = 1
while i<=9:
j=1
while j<=i:
print("%d*%d=%2d "%(i,j,i*j),end=‘‘)
j+=1
print()
i+=1
print(‘----------------------------------------------------‘)
#方向二(右下角)
i = 1
while i<=9:
k=1
while k<=9-i:
print(‘ ‘,end=‘‘)
k+=1
j=1
while j<=i:
print("%d*%d=%2d "%(i,j,i*j),end=‘‘)
j+=1
print()
i+=1
print(‘---------------------------------------------------‘)
#方向三(左上角)
i = 9
while i>=1:
j=1
while j<=i:
print("%d*%d=%2d "%(i,j,i*j),end=‘‘)
j+=1
print()
i-=1
print(‘---------------------------------------------------‘)
#方向四(右下角)
i = 9
while i>=1:
k=1
while k<=9-i:
print(‘ ‘,end=‘‘)
k+=1
j=1
while j<=i:
print("%d*%d=%2d "%(i,j,i*j),end=‘‘)
j+=1
print()
i-=1
# for...in循环
# 方向一(左下角)
for i in range(1,10):
for j in range(1,i+1):
print(‘%d*%d=%2d ‘ %(i,j,i*j),end = ‘‘)
print()
print(‘---------------------------------------------------------‘)
#方向二(左上角)
for i in range(1,10):
for j in range(i,10):
print(‘%d*%d=%2d ‘ %(i,j,i*j),end = ‘‘)
print()
print(‘-----------------------------------------------------‘)
#方向三(右下角)
for i in range(1,10):
for k in range(i,9):
print(end = ‘ ‘)
for j in range(1,i+1):
print(‘%d*%d=%2d ‘ %(i,j,i*j),end = ‘‘)
print()
print(‘---------------------------------------------------------‘)
#方向四(右上角)
for i in range(1,10):
for k in range(1,i):
print(end=‘ ‘)
for j in range(i,10):
print(‘%d*%d=%2d ‘ %(i,j,i*j),end = ‘‘)
print()
标签:bsp 乘法 end nbsp -- += 乘法表 for 位置
原文地址:http://www.cnblogs.com/sihulu/p/7822629.html