python3.3实现乘法表示例

代码如下:

from stringhelper import padleft for x in range(1,10): for y in range (1,x+1): endflag=’ | \n’ if x==y else ‘ | ‘ print(y,’*’,x,’=’,padleft( str(x*y),2,’ ‘),end=endflag)

stringhelper.py

代码如下:

# -*- coding: utf8 -*-”’扩展为c#中的string.padleft”’def padleft(str, num, padstr): stringlength = len(str) n = num – stringlength if n >= 0: str = padstr*n + str return str

效果图:

发表评论