Home  >  Article  >  Backend Development  >  Python outputs the multiplication table

Python outputs the multiplication table

angryTom
angryTomOriginal
2019-10-21 17:44:3515509browse

Python outputs the multiplication table

Python outputs the multiplication table

Define two levels of loops, the outer loop is from 1 to 9, the inner loop is controlled by the outer loop, and then Calculate the product of the inner and outer loop variables, and finally format the output.

for i in range(1,10): # 设置循环次数
    row = ""
    for j in range(1,i+1):
        row += "{0}*{1}={2} ".format(j,i,i*j)
    print(row)  # 输出每行数据

Recommended: 《python tutorial》

The above is the detailed content of Python outputs the multiplication table. For more information, please follow other related articles on the PHP Chinese website!

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