Python

Python作品03-列印三角圖形

Python作品03-列印三角圖形

列印三角圖形

•設計說明:

請撰寫一程式,讓使用者輸入一個數字n,則用@字元列印出n 層的反直角三角形

image

# -*- coding: utf-8 -*-
"""
Created on Fri Nov 13 16:16:08 2020

@author: shou
"""
n = int(input("請輸入數字:"))
for i in range(n):
    print("@"*(n-i))

#改用while改寫
n = int(input("請輸入數字:"))
i = 0
while i <=n:
    print("@"*(n-i))
    i+=1

•設計說明:

請撰寫一程式,讓使用者輸入一個數字n,則用@字元列印出n 層的反直角三角形

image

# -*- coding: utf-8 -*-
"""
Created on Mon Nov 16 15:07:26 2020

@author: shou
"""

n = int(input("請輸入數字:"))
for i in range(1,n+1):
    print(" "*(i)+"@"*(n-i))

•設計說明:

請撰寫一程式,讓使用者輸入一個數字n,則用@字元列印出n 層的等腰三角形

image

# -*- coding: utf-8 -*-
"""
Created on Mon Nov 16 15:10:30 2020

@author: shou
"""
#等腰三角形
n = int(input("請輸入數字:"))
for i in range(1,n+1):
    print(" "*(n-i)+"@"*(i)+"@"*(i-1))
    
#菱形
n = int(input("請輸入數字:"))
for i in range(1,n+1):
    print(" "*(n-i)+"@"*(i)+"@"*(n-i))
comments powered by Disqus
| copyright © 2020 Themefisher All Rights Reserved |