代码如下: 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