Home>Article>Backend Development> 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:
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!