Print '99 multiplication table' with Python multimethod

Most students who learn pyhon feel that they can understand it as soon as they learn it, and it will be useless if they write it by themselves.

The main reason is that there is less code to write. Projects that are too complicated, learning and research are too difficult, will hinder our confidence in learning

Today I will teach you to write some simple small cases to consolidate your basic knowledge

Come on boy, write enough 5000 lines to pass the basic level


The first:

for i in range(1,10):
#1-9 包头不包尾
    for m in range(1,i+1):
        print("%d*%d=%d"%(m,i,m*i),end="    ")
#计算排版
    print()

The second type:

for i in  range(1,10):
    for m in range(1,i+1):
        #start:1  end:2  运行循环一次
        #m=1   i=1   1*1=1
        print("%d*%d=%d"%(m,i,(m*i)),end=" ")
    print()

Print the ninety-nine multiplication table
Determine the start position and end position
start: 1 (start) end: 10 (end)


The third type:


for i in range(1,10):
    for m in range(1,i+1):
        print("%d*%d=%d"%(m,i,m*i),end="   ")
    print()

Idea: Nested loops
First point: Determine the number of outer loops
    for i in range (1,10)
Second point: Nested loops for
    range (1, i+1)
Third point: Print in the inner loop ( operator, placeholder), without line break operation
Fourth point: In the outer loop, write a line break statement


The fourth type:

for i in range(1,10):
    for n in range(1,1+i):
        print("%d*%d=%d"%(n,i,n*i),end="    ")
    print()

Guess you like

Origin blog.csdn.net/Sjm05/article/details/127445734