Python - 打印等边三角形,九九乘法表,4行代码以内搞定

1. 打印等边三角形,代码:

equilateral_triangle_height = int(input('Please input an odd number (triangle height): '))
for i in range(equilateral_triangle_height, 0, -1):
    print(i*' '+(equilateral_triangle_height-i+1)*'* ')

结果:

image

2. 打印九九乘法表,代码:

for i in range(1,10):
    for j in range(1, i+1):
        print(f'{j} x {i} = {i*j}', end="\t")
    print()

 

结果:

image

posted @ 2020-06-08 19:44  Johnthegreat  阅读(1099)  评论(0编辑  收藏  举报