---
# System prepended metadata

title: 2019/09/24

---

# 2019/09/24
使用 Python 印出菱形
```python
num=input()
for i in range(num):
    for j in range(num-(i+1)):
        print " ",
        j += 1
    for k in range((num-1)*i+1):
        if k>=2*i+1 :
            print " ",
        else:
            print "*",
        k += 1
    print "\n"
i += 1

for i in range(num-1):
    for j in range(i+1):
        print " ",
        j += 1
    for k in range(2*((num-1)-i)-1):
        print "*",
        k += 1
    print "\n"
i += 1
```
![](https://i.imgur.com/JgOjbCG.png)
![](https://i.imgur.com/BjUjjve.png)
![](https://i.imgur.com/a2BVxME.png)

使用 Python 印出圖形
```python
num = input()
for i in range(num,0,-1):
	for j in range(num*3):
		if (j<i):
			print "*",
		else:
			print " ",
	i-=1
	print "\n"
for i in range(0,num+1):
	for j in range(num*3,0,-1):
		if (j>i):
			print " ",
		else:
			print "*",
	i-=1
	print "\n"
```
![](https://i.imgur.com/v1jnIqo.png)
![](https://i.imgur.com/kZcRPza.png)
![](https://i.imgur.com/yDnWMAj.png)
寫一個 Python Function
```python
num = input()
size = len(str(num))
for i in range(size,0,-1):
	strnum = str(num)
	print strnum[-i],
	print "*1",
	for j in range(1,i):
		print "0",
	if(i!=1):
		print "+",
```
![](https://i.imgur.com/Q4qqf1c.png)
