---
# System prepended metadata

title: 練習文字圖形
tags: [python]

---

---
tags: python
---
# 練習文字圖形
##  練習1
![](https://i.imgur.com/eep1vPQ.png)

```python=
for i in range(1,6):
    for k in range(i):
        print("*",end="")
    print()
```
---


##  練習2
![](https://i.imgur.com/2j6W772.png)

```python=
for i in range(-4,5):
    for k in range(-4,5):
        if (abs(i)+abs(k)) <= 4 and (abs(i)+abs(k))%2 == 0:
            print("*",end="")
        else:
            print(" ",end="")
    print()
```
---


##  練習3
![](https://i.imgur.com/YbIpc2L.png)

```python=
for i in range(1,6):
    for k in range(i):
        print(i,end="")
    print()
```
---


##  練習4
![](https://i.imgur.com/J6hB2dL.png)
```python=
for i in range(-4,5):
    for k in range(-4,5):
        if abs(i)+abs(k) <=abs(i)*2:
            print(abs(i)+1,end="")
        else:
            print(abs(k)+1,end="")
    print()
```
---


##  練習5
![](https://i.imgur.com/qcOukGc.png)

```python=
for i in range(1,6):
    for k in range(i):
        print(chr(64+i),end="")
    print()
```
---


##  練習6
![](https://i.imgur.com/sJTS67O.png)

```python=
for i in range(5):
    print(chr(65+i))
print()
for i in range(5):
    print(chr(65+i),end="")
```
---


##  練習7
![](https://i.imgur.com/rkoL1ot.png)

```python=
for k in range(1,4):
    for i in range(3):
        for j in range(3*k):
            if j%3<=i:
                print("*",end="")
            else:
                print(" ",end="")
        print()
```
思考方向：先畫出下圖
![](https://i.imgur.com/2SzK0Hx.png)
　　　　012345678
第一行→ x□□x□□x□□
第二行→ xx□xx□xx□
第三行→ xxxxxxxxx
```python=
for i in range(3):            #印第i行
    for j in range(9):        #印第j列 口口口口口口口口口
        if j%3<=i:            #i是0一顆*，i是1二顆*，i是2三顆星
            print("*",end="")
        else:
            print(" ",end="")
    print()
```
---


##  練習8
![](https://i.imgur.com/dYjapjr.png)

```python=
for i in range(7):
    for j in range(-7,7):
        if abs(i)==abs(j):
            print("*",end="")
        else:
            print(" ",end="")
    print()
print("*"+" *"*(i+1))
```
```python=
for i in range(1,8):
    print((8-i)*" "+"*"+(((i-1)*2)-1)*" "+(i>1)*"*")
print((i+1)*"* ")

```
---


##  練習9-0
![](https://i.imgur.com/JG5Cp0V.png)

```python=
for i in range(-4,5):
    print(" "*(4-abs(i))+"*"*(2*abs(i)+1))
```
---


##  練習9-1
![](https://i.imgur.com/gJQroxR.png)

```python=
for i in range(-4,5):
    for j in range(-4,5):
        if abs(j)%5>=abs(i):
            print("*",end="")
        else:
            print(" ",end="")
    print()
```
同場加映
![](https://i.imgur.com/i1cZtqA.png)

```python=
for i in range(-4,5):
    for j in range(-5,5):
        if j%5>=abs(i):
            print("*",end="")
        else:
            print(" ",end="")
    print()
```
---


##  練習9-2
![](https://i.imgur.com/K4gDe81.png)
```python=
for i in range(-4,5):
    for j in range(-4,5):
        if abs(j)+abs(i)>=4:
            print("*",end="")
        else:
            print(" ",end="")
    print()
```
---


##  練習10
![](https://i.imgur.com/K7gZhOG.png)

```python=
for i in range(-7,1):
    for j in range(-7,8):
        if abs(i)>=abs(j) and j!=0:
            print("*",end="")
        else:
            print(" ",end="")
    print()
```
---


##  練習11
![](https://i.imgur.com/0nvQGxx.png)

```python=
for i in range(1,6):
    print(" "*(5-i) + " *"*i + " "*(5-i)*2 + " *"*i)
```
---


##  練習12
![](https://i.imgur.com/Epv7ErJ.png)

```python=
for i in range(5,0,-1):
    for j in range(i):
        print(chr(70-i),end="")
    print()
```

```python=
for i in range(5,0,-1):
    print(chr(70-i)*i)
```
---


##  練習13
![](https://i.imgur.com/3LQnQLw.png)

```python=
for i in range(1,6):
    for j in range(i,2*i):
        print(j%2,end="")
    print()
```
---


##  練習14
![](https://i.imgur.com/dYHFFyz.png)

```python=
for i in range(1,6):
    for j in range(1,6):
        if i==j:
            print("0",end="")
        else:
            print(i,end="")
    print()
```
---


##  練習15
![](https://i.imgur.com/APvgyCa.png)

```python=
for i in range(5):             #跑第幾行(row)，第 0 層到 4 層
    strs=""                    #每層迴圈字串清空
    sum=0                      #每層迴圈數字歸零
    for j in range(2*i+1):     #跑第幾列(Column)
        if j>(2*i+1)/2:
            s=-1               #如果超過一半開始遞減
        else:
            s=1                #未過半則遞增
        sum = sum + s          #計算個別數字
        strs=strs + str(sum)   #將個別數字合併為字串 
    print(" "*(4-i) + strs)
```
```python=
for i in range(5):             #跑第幾行(row)，第 0 層到 4 層
    print(" "*(4-i),end="")    #每行先印空白
    sum=0                      #每層迴圈數字歸零
    for j in range(2*i+1):     #跑第幾列(Column)
        if j>(2*i+1)/2:
            s=-1               #如果超過一半開始遞減
        else:
            s=1                #未過半則遞增
        sum = sum + s          #計算個別數字
        print(sum,end="") 
    print()
```
---


##  練習16
![](https://i.imgur.com/6p0qPAU.png)

```python=
for i in range(5):
    print(" "*(4-i)+str(5-i)*(i+1))
```
---


##  練習17
![](https://i.imgur.com/aOEe8yR.png)

```python=
sum=0
for i in range(5):
    for j in range(i+1):
        sum=sum+1
        if sum<10:
            strs=" "+str(sum)
        else:
            strs=str(sum)
        print(strs + " ",end="")
    print()
```
---


##  練習18
![](https://i.imgur.com/Md7mWvd.png)

```python=
for i in range(6):
    for j in range(-5,6):
        if abs(j)>=abs(i):
            print(chr(70-abs(j)),end="")
        else:
            print(" ",end="")
    print()
```
---


##  練習19
![](https://i.imgur.com/wzYP6go.png)

```python=
strs="SCHOOL"
for i in range(6):
    for j in range(i+1):
        print(strs[j],end="")
    print()
```
---


##  練習20
![](https://i.imgur.com/RH5U3EB.png)

```python=
for i in range(-4,5):
    for j in range(-4,5):
        if abs(i)==abs(j):
            print(chr(97+abs(i)),end="")
        else:
            print(" ",end="")
    print()
```
---


##  習題01
![](https://i.imgur.com/EmqSFWj.png)

```python=
for i in range(-4,5):
    for j in range(5-abs(i)):
        print(j+1,end="")
    print()
```
---


##  習題02
![](https://i.imgur.com/9mXpaM7.png)

```python=
for i in range(1,6):
    print(" "*(5-i) + "*"*i)
```
---


##  習題03
![](https://i.imgur.com/LBakMjb.png)

```python=
for i in range(-4,5):
    for j in range(5-abs(i)):
        print(chr(j+97),end="")
    print()
```
---


##  習題04
![](https://i.imgur.com/K6zRZb2.png)

```python=
for i in range(-2,3):
    print(" "*abs(i) + "* "*(3-abs(i)))
```
---


##  習題05
![](https://i.imgur.com/BN6fjlL.png)

```python=
for i in range(-4,5):
    for j in range(-4,5):
        if 4 - abs(j) <= abs(i):
            print("*",end="")
        else:
            print(" ",end="")
    print()
```
---