Python 3.3 乘法表

1 from StringHelper  import PadLeft 
2 for x in range(1,10):    
3     for y in  range (1,x+1):        
4         endflag='  |  \n' if x==y else '  |  '
5         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

 输出结果

 Python 3.3 乘法表_第1张图片

 

 

 

 

你可能感兴趣的:(python)