Use Python loop (including while & for) to print the 9-9 multiplication table instances, pythonwhile

Source: Internet
Author: User

Use Python loop (including while & for) to print the 9-9 multiplication table instances, 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 (): for k in range (I +): 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 (): for k in range (1, I): print (end = '') # Eight spaces 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.1 lower 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 = '') # 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 = '') # 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.

The above example of printing the 9-9 multiplication table using the Python loop (including while & for) is all the content shared by the editor. I hope to give you a reference, we also hope that you can support the customer's home.

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.