Write all kinds of graphics in shell or Python

Source: Internet
Author: User

First, the shell.


Equilateral triangle

[[email protected] my_script]# sh ff.shnum:6     *     ***   *****  ******* ********************[[email protected]  my_script]# cat ff.sh#!/bin/bash############################################################## ############ file name: ff.sh# author: huxianyong# mail: [email  protected]# created time: 2017 June 07   Wednesday  16 41 minutes, 14 seconds ################################## ###################################### #read  -p  "num:"  numfor ((i=1;i<= $num; i++)) Dofor ((j= $num (j>i;j--)) doecho -e  " \c" Donefor ((l=1;l<=i;l++)) doecho -e  "*\c" Donefor ((r=1;r <i;r++)) doecho -e  "*\c" Doneechodone or read -p  "num:"  numfor ((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     echodone
[[Email protected] my_script]# SH ff.shnum:6 * * * * * * * * * * * * * * * * * * * * * * * * *[[email protected] My_scrip t]# Cat ff.sh#!/bin/bash########################################################################## File Name:ff.sh # author:huxianyong# Mail: [email protected]# Created time:2017 June 07 Wednesday 16:41 14 seconds ################################## ###################################### #read-P "num:" Numfor ((i=1;i<= $num; i++)) Dofor ((j= $num; j>i;j--)) Doecho-e "\c" Donefor ((l=1;l<=i;l++)) doecho-e "* \c" Doneechodone

Isosceles Right Triangle

[[Email protected] my_script]# sh ff.shnum:5*************************[[email protected] my_script]# cat ff.sh#!/bin/ bash########################################################################## File name:ff.sh# Author:huxianyong # Mail: [email protected]# Created time:2017 June 07 Wednesday 16:41 14 seconds #################################################### #################### #read-P "num:" Numfor ((i=1;i<= $num; i++)) Do for ((l=1;l<=2*i-1;l++)) do echo-e "*\c "Done Echodone

Rhombic

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&nBSP; ""      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

The other shapes are similar.

Python print Diamond

* * * * * * * * * * * * * * * * *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))


This article is from the "Forand" blog, make sure to keep this source http://853056088.blog.51cto.com/12966870/1933243

Write all kinds of graphics in shell or Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.