How to print the multiplication table in Python

Release: 2019-07-08 09:05:44
Original
16782 people have browsed it

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()
Copy after login

The running results are as follows:

How to print the multiplication table in Python

For more Python-related technical articles, please visit the Python Tutorial column 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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!