Python Output 99 multiplication table

Source: Internet
Author: User

1. The script is as follows

(1) Inverted triangular format, note the space before the line

For I in Range (1,10):
For j in Range (i,10):
Print ("%d*%d=%d"% (i,j,i*j), end= "")
Print ("")

(2) Rectangular format

For I in Range (1,10):

For j in Range (1,10):

Print ("%d*%d=%2d"% (i,j,i*j), end= "")

Print ("")

(3)

Rectangular format

For I in Range (1,10):

For j in Range (1,10):

Print ("%d*%d=%d"% (i,j,i*j), end= "")

Print ("")

(4) Other formats

For I in Range (1,10):

For j in Range (1,10):

Print ("%d*%d=%d"% (i,j,i*j))

Print ("")

Summarize:

1, inverted triangle and rectangle difference lies in the range of J, when J in Range (i,10):, at this time, each time the loop is executed, I increase at the same time, J also increased, but if J in range (1,10), each time, J is from 1 to 9 execution once

2, end= "", pass an empty string for end end, so that the print function does not add a line break at the end of the string, but instead adds an empty string. This only works with version 3. 2.* Version not supported

3, the last line print (""), the main role of line-wrapping

Python Output 99 multiplication table

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.