python-printing 99 multiplication table with for loop, while loop, and one sentence

Source: Internet
Author: User

To print the 99 multiplication table with a For loop:

For I in Range (1,10):    for J in Range (1,i+1):        print ('%s*%s=%s '% (j,i,i*j), end= ' \ t ')    print ()
Print results
1*1=11*2=22*2=41*3=32*3=63*3=91*4=42*4=83*4=124*4=161*5=52*5=103*5=154*5=205*5=251*6=62*6=123*6=184*6=245*6= 306*6=361*7=72*7=143*7=214*7=285*7=356*7=427*7=491*8=82*8=163*8=244*8=325*8=406*8=487*8=568*8=641*9=92*9=183*9 =274*9=365*9=456*9=547*9=638*9=729*9=81

  The while loop prints the 99 multiplication table:

I=0j=0while i<9:    i+=1 while    j<9:        j+=1        Print (J, "X", I, "=", i*j, "\ T", end= "")        if i==j:            J =0            Print ("")            break

  The printing results are:

1 x 1 = 1  1 x 2 = 2   2 x 2 = 4  1 x 3 = 3   2 x 3 = 6   3 x 3 = 9 1 x 4 = 4 2 x   4 = 8   3 x 4 =  4 x 4 = 1 x 5 = 5 2 x 5 = 3  x 5 = 4 x  5 = 5 x 5 = 1 x 6 = 6   2 x 6 = 1 2  3 x 6 =  4 x 6 = 5  x 6 = 6 x  6 = 1 x 7 = 7   2 x 7  = 3 x 7 = x 4 = 7 8  5 x 7 =  6 x 7 =  7 x 7 = 1 x 8 = 8   2 x 8 =  3 x 8 = 4 x 8 = 5 8 0  6 x 8 = 7 x 8 = 8 x 8 = 1 x 9 =  9 2 x 9 = 3 x 9 = 4 x 9 =  5 x 9 = 4 5  6 x 9 =  7 x 9 =  8 x 9 = 9  x 9 = 81

  Print the 99 multiplication table in a sentence:

Print (' \ n '. Join (['%s*%s=%-2s '% (y,x,x*y) for Y in range (1,x+1)]) "For X in range (1,10)))

  The printing results are:

1 x 1 = 1  1 x 2 = 2 2   x 2 = 4  1 x 3 = 3   2 x 3 = 6   3 x   3 = 9 1 x 4 = 4 2 x 4 = 8  4 x 4 = 1 x 5 = 5   2 x 5 = 3  x 5 =  4 x 5 = 5 x 5 = 1 6 x 6  X 6 =  4 x 6 =  5 x 6 =  6 x 6 = 1 x 7 = 7   2 x 7 = 3  x 7 = 4 x 7 = 5  X 7 =  6 x 7 =  7 x 7 = 1 x 8 = 8   2 x 8 = 3  x 8 =  4 x 8 = 5  x 8 =  6  X 8 =  7 x 8 = 8 x 8 = 1 x 9 = 9 2 x 9 = 3  x 9 =  4 x 9 =  5 x 9 =  6 X 9 =  7 x 9 =  8 x 9 = 9  x 9 = 81

  

python-printing 99 multiplication table with for loop, while loop, and one sentence

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.