Print the 9-9 multiplication table and pythonwhile using Python loops (including while & amp;)

Source: Internet
Author: User

Print the 9-9 multiplication table using Python loops (including while & for) and pythonwhile

I. Print the 9-9 multiplication table in a for Loop

# Note: Due to the poor control of indentation in the browser, please forgive me. images will be imported later.

1.1 lower left corner

For I in range (1, 10 ):

For j in range (1, I + 1 ):

Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
Print ()

:

 

1.2 bottom right corner

For I in range (1, 10 ):
For k in range (I + 1, 10 ):
Print (end = '') # Eight spaces are returned. Note that
For j in range (1, I + 1 ):
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
Print ()

 

 

 

1.3 upper left corner

For I in range (9, 0,-1 ):
For j in range (1, I + 1 ):
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
Print () # The main purpose here is to use the print feature for line feed.

 


1.4 upper right corner
For I in range (1, 10 ):
For k in range (1, I ):
Print (end = '') # Eight spaces are returned.
For j in range (9, I-1,-1 ):
Print ('% d * % d = % 2d \ t' % (I, j, I * j), end = '')
Print ()

 

 

Ii. while loop print multiplication table (four methods)

2.1Lower left corner

I = 1
While I <= 9:
J = 1
While j <= I:
Print ('% d * % d = % 2d \ t' % (I, j, I * j), end = '')
J + = 1
Print ()
I + = 1

:

 


2.2 bottom right corner
I = 1
While I <= 9:
K = 9
While k> I:
Print (end = '') # There are eight spaces.
K-= 1
J = 1
While j <= I:
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
J + = 1
Print ()
I + = 1

 

2.3 upper left corner
I = 9
While I> = 1:
J = 1
While j <= I:
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
J + = 1
I-= 1
Print ()


2.4 upper right corner
I = 9
While I> = 1:
K = 9
While k> I:
Print (end = '') # There are eight spaces.
K-= 1
J = 1
While j <= I:
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
J + = 1

Print ()
I-= 1

 

 

 

 

 

Later: the source code is used for reference only.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.