一. 九九乘法表

a = 1
while a <=9:    #外层循环控制行数
    b = 1
    while b <= a:   #内层循环控制列数
        print("%dx%d=%d\t" % (a, b, a*b), end="")
        b = b + 1
    print()     # 换行
    a = a + 1

#结果:

二. 三角形

a = 1
while a <=5:    #控制行数
    b = 1
    while b <=a:    #列数
        print('*',end='')
        b +=1
    print()    #换行
    a+=1

#结果:

a = 1
while a <=5:
    b = 5
    while b >= a:
        print('*',end='')
        b -=1
    print()
    a +=1

#结果:

a = 1
while a <=9:
    b =0
    c =1
    while b <= 9-a:
        print(' ' ,end='')
        b +=2
    while c <=a:
        print('*',end='')
        c+=1
    print()
    a+=2

#结果:

 

转载于:https://www.cnblogs.com/dong-/p/9349905.html