使用while实现打印直角三角形


"""
    使用while实现打印直角三角形
    要求输入一个整数表示三角形的宽和高,打印出如下的三种直角三角形
    1)
       *
      **
     ***
    ****
    2)
    ****
    ***
    **
    *
    3)
    ****
     ***
      **
       *
"""
high_bottom = int(input('请输入直角三角形的高(高和底相等的直角三角形):'))
count_1 = 1 # 计数器
count_2 = 0 # 计数器
count_3 = 0 # 计数器
reciprocal = high_bottom
#第一个
print('--------第一个三角形--------')
while count_1 <= high_bottom:
    space = high_bottom -count_1
    print(' ' * space +'*' * count_1)
    count_1 +=1
#第二个
print('--------第二个三角形--------')
while count_2 < high_bottom:
    asterisk = high_bottom -count_2
    print('*' * asterisk + ' ' * count_2)
    count_2 +=1
#第三个
print('--------第三个三角形--------')
while count_3 < high_bottom:
    asterisk = high_bottom -count_3
    print(' ' * count_3 + '*' * asterisk)
    count_3 +=1

 


免责声明!

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



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