Python 练习:使用 * 输出直角三角形


正方向

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

测试结果:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM