标签:
1.请用shell或Python编写一个正方形(oldboy4.sh),接收用户输入的数字。
例如:用+号实现
xiaorui@xiaorui:~/script$ vim oldboy_squarel.sh xiaorui@xiaorui:~/script$ ./oldboy_squarel.sh Please Enter a number:4 ++++++++ ++++++++ ++++++++ ++++++++ xiaorui@xiaorui:~/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),接收用户输入的数字。
例如:用*号实现
xiaorui@xiaorui:~/script$ vim oldboy2_triangle.sh xiaorui@xiaorui:~/script$ ./oldboy2_triangle.sh Please Enter the num:3 * *** ***** xiaorui@xiaorui:~/script$ ./oldboy2_triangle.sh Please Enter the num:5 * *** ***** ******* ********* xiaorui@xiaorui:~/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
标签:
原文地址:http://www.cnblogs.com/migongci0412/p/5016869.html