1.请用shell或Python编写一个正方形(oldboy4.sh),接收用户输入的数字。
例如:用+号实现
[email protected]:~/script$ vim oldboy_squarel.sh [email protected]:~/script$ ./oldboy_squarel.sh Please Enter a number:4 ++++++++ ++++++++ ++++++++ ++++++++ [email protected]:~/script$ cat oldboy_squarel.sh #/biin/bash read -p "Please Enter a number:" num for ((i=0;i<$num;i++)) { for((j=0;j<$num*2;j++)) { echo -n "+" } echo }
2.请用shell或Python编写一个等腰三角形(oldboy2_triangle.sh),接收用户输入的数字。
例如:用*号实现
[email protected]:~/script$ vim oldboy2_triangle.sh [email protected]:~/script$ ./oldboy2_triangle.sh Please Enter the num:3 * *** ***** [email protected]:~/script$ ./oldboy2_triangle.sh Please Enter the num:5 * *** ***** ******* ********* [email protected]:~/script$ cat oldboy2_triangle.sh #/bin/bash read -p "Please Enter the num:" num for ((i=0;i<$num;i++)) { for ((j=0;j<$num-$i;j++)) { echo -n " " } for ((k=0;k<$i*2+1;k++)) { echo -n "*" } echo }
原题来源:http://oldboy.blog.51cto.com/2561410/1718607
时间: 2024-10-14 15:17:42