复制代码 代码如下:
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(xy),2,' '),end=endflag)
StringHelper.py
复制代码 代码如下:
'''
扩展为C#中的String.PadLeft
'''
def PadLeft(str, num, padstr):
stringlength = len(str)
n = num - stringlength
if n >= 0:
str = padstr*n + str
return str
效果图:
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8