Home >Backend Development >Python Tutorial >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!