您的位置:首页 > 编程语言 > Python开发

python学习-乘法口诀

2016-12-05 19:18 134 查看
# reference : introduction to programming using python(Y.Daniel Liang)

正方形形状的表现方法(乘法口诀中有重复项)

print(' Multiplication Table')

# display the number title

print('   ',end=' ')

for j in range(1,10):

print('   ',j,end='')
print()# jump to the new line

print('--------------------------------------------------')

for i in range(1,10):

print(i,'|',end=' ')

for j in range(1,10):

print(format(i*j,"4d"),end=' ')

print()

三角形形状的表现方法

for i in range(1,10):

for j in range(1,10):

if (j<=i):

print(format(i,'2d'),'×',format(j,'2d'),'=',format(i*j,'2d'),' ',end=' ')

print()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: