Home>Article>Backend Development> How to print the multiplication table in Python

How to print the multiplication table in Python

尚
Original
2019-06-27 11:12:23 16703browse

How to print the multiplication table in Python

Define a variable i to set the loop from 1 to 9. Then set the second variable j, and also set up a loop, ranging from 1 to i 1. Then print out the value of i, the value of j, and the product of the two numbers in the form of a multiplication formula, so that both the inner and outer loops are completed.

# 外层循环控制打印9行 for i in range(1, 10): # 内存循环控制每一行如何打印 for j in range(1, i+1): print('{}x{}={}'.format(j, i, i*j), end=' ') print()

The running results are as follows:

How to print the multiplication table in Python

For more Python-related technical articles, please visit thePython Tutorialcolumn to learn!

The above is the detailed content of How to print the multiplication table in Python. 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