Home >Backend Development >Python Tutorial >python3.3实现乘法表示例

python3.3实现乘法表示例

WBOY
WBOYOriginal
2016-06-16 08:45:201205browse

复制代码 代码如下:

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


效果图:
python3.3实现乘法表示例
 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn