首先是shell
等边三角形
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
[root@hxy my_script] # sh ff.sh
num:6 *
***
*****
*******
*********
*********** [root@hxy my_script] # cat ff.sh
#!/bin/bash ######################################################################### # File Name: ff.sh # Author: huxianyong # mail: hxy123@163.com # Created Time: 2017年06月07日 星期三 16时41分14秒 ######################################################################### read -p "num:" num
for ((i=1;i<=$num;i++))
do for ((j=$num;j>i;j--))
do
echo -e " \c"
done
for ((l=1;l<=i;l++))
do
echo -e "*\c"
done
for ((r=1;r<i;r++))
do
echo -e "*\c"
done
echo
done 或者 read -p "num:" num
for ((i=1;i<=$num;i++))
do for ((j=$num;j>i;j--))
do
echo -e " \c"
done
for ((l=1;l<=2*i-1;l++))
do
echo -e "*\c"
done
echo
done |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
[root@hxy my_script] # sh ff.sh
num:6 *
* *
* * *
* * * *
* * * * *
* * * * * * [root@hxy my_script] # cat ff.sh
#!/bin/bash ######################################################################### # File Name: ff.sh # Author: huxianyong # mail: hxy123@163.com # Created Time: 2017年06月07日 星期三 16时41分14秒 ######################################################################### read -p "num:" num
for ((i=1;i<=$num;i++))
do for ((j=$num;j>i;j--))
do
echo -e " \c"
done
for ((l=1;l<=i;l++))
do
echo -e "* \c"
done
echo
done |
等腰直角三角形
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
[root@hxy my_script] # sh ff.sh
num:5 * *** ***** ******* ********* [root@hxy my_script] # cat ff.sh
#!/bin/bash ######################################################################### # File Name: ff.sh # Author: huxianyong # mail: hxy123@163.com # Created Time: 2017年06月07日 星期三 16时41分14秒 ######################################################################### read -p "num:" num
for ((i=1;i<=$num;i++))
do for ((l=1;l<=2*i-1;l++))
do
echo -e "*\c"
done
echo
done |
菱形
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
for ((i = 1; i < 12; i++))
do
if [[ $i - le 6 ]]; then
for ((j = $((12-i)); j > i; j--))
do
echo -n " " ;
done
for ((m = 1; m <= $((2*i-1)); m++))
do
#echo -n "$i "
echo -n "* "
done
echo ""
elif [[ $i -gt 6 ]]; then
n=$((12-i))
for ((j = $((12-n)); j > n; j--))
do
echo -n " " ;
done
for ((m = 1; m <= $((2*n-1)); m++))
do
#echo -n "$i "
echo -n "* "
done
echo ""
fi
done
|
其他的形状大同小异了
python打印菱形
1
2
3
4
5
6
7
8
9
10
11
12
13
|
*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
s = '*'
for i in range ( 1 , 8 , 2 ):
print ((s * i).center( 7 ))
for i in reversed ( range ( 1 , 6 , 2 )):
print ((s * i).center( 7 ))
|
利用python打印空心正方形
1
2
3
4
5
6
7
8
9
|
#encoding=utf-8 num = input ( "please input you number: " )
b = c = int (num)
print ( " * " * int (num))
while 0 < c - 2 :
c - = 1
print ( " * " + " " * (b - 2 ) + " * " )
print ( " * " * int (num))
|