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

Python outputs the multiplication table

angryTom
Release: 2019-10-24 17:55:30
Original
15568 people have browsed it

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)  # 输出每行数据
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template