python write a multiplication table

python write a multiplication table

background

Recently seen on a single line of code can do, where there is a multiplication table to write a single line of code, so think of the three lines Kechuang mission, it is necessary to reproduce the multiplication table and slightly altered the print . FIG effect as
Here Insert Picture Description

The complete code

for i in range(1,10):
    for j in range(1,i+1):
        print("%dx%d=%2d"%(j,i,i*j),end="  ")
    print("")

Code Reading

The whole loop and the code only to the print function, j is represented by a first multiplier, a second multiplier denoted i and i + 1 with j to control the range of laying down line by line, a back end two spaces, used to adjust the spacing renderings of each column, the second print function is used to wrap otherwise, all multiplications are written on the same line above, it is not very interesting, quickly moving hands and try to write about.

After words

Welcome friends to provide more clues to the works or three lines Kechuang, let us produce more interesting mathematical product.

Retrospect on how to find the list of the longest string

Published 45 original articles · won praise 12 · views 8688

Guess you like

Origin blog.csdn.net/zengbowengood/article/details/97034263