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 乘法表

 

 

 

 

相关文章:

  • 2021-08-22
  • 2021-11-10
  • 2022-02-27
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-06-08
猜你喜欢
  • 2021-08-13
  • 2022-01-13
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案