使用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