使用 * 输出直角三角形

Posted klvchen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用 * 输出直角三角形相关的知识,希望对你有一定的参考价值。

正方向

height = int(input("please input height: "))

tmp = 1
while tmp <= height:
    width = tmp
    while width > 0:
        print("*", end="")
        width -= 1
    print("")
    tmp += 1

测试结果:

 

反方向:

height = int(input("please input height: "))

while height > 0:
    tmp = height
    while tmp > 0:
        print("*",end="")
        tmp -= 1
    print()
    height -= 1

测试结果:

以上是关于使用 * 输出直角三角形的主要内容,如果未能解决你的问题,请参考以下文章