用python打印各种图形

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用python打印各种图形相关的知识,希望对你有一定的参考价值。

#用python打印出直角三角形:

  1 #!/usr/bin/env python
  2 # coding=utf-8
  3 i = 0
  4 while i < 5:
  5     j = 0
  6     while j <= i:
  7         print "*",
  8         j+=1
  9     print ""
 10     i+=1             
 
 输出效果如下:
* 
* * 
* * * 
* * * * 
* * * * *

#对上面的程进行深化,可以得到两个相对的三角形:

#!/usr/bin/env python
  2 # coding=utf-8
  3 i = 0
  4 while i < 5:
  5     j = 0
  6     while j <= i:
  7         print "*",
  8         j+=1
  9     print ""
 10     i+=1
 11 i = 5·
 12 while i > 0:
 13     j = 0
 14     while j <= i:
 15         print "*",
 16         j+=1                                                                                                                                  
 17     print ""
 18     i-=1

输出结果如下:

* * 

* * * 

* * * * 

* * * * * 

* * * * * 

* * * * 

* * * 

* * 

#最后上个心形:

print‘\n‘.join([‘‘.join([(‘PYTHON!‘[(x-y)%7]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else‘ ‘)for x in range(-30,30)])for y in range(15,-15,-1)])

输出结果如下:

                                                            
                                                            
                THON!PYTH           YTHON!PYT               
            !PYTHON!PYTHON!PY   N!PYTHON!PYTHON!P           
          N!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTH         
         N!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON        
        N!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!P       
        !PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PY       
        PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYT       
        YTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTH       
        THON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHO       
        HON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON       
         N!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON        
          PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON         
          YTHON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON!         
            ON!PYTHON!PYTHON!PYTHON!PYTHON!PYTHON           
             !PYTHON!PYTHON!PYTHON!PYTHON!PYTHON            
              YTHON!PYTHON!PYTHON!PYTHON!PYTHON             
                ON!PYTHON!PYTHON!PYTHON!PYTHO               
                  PYTHON!PYTHON!PYTHON!PYTH                 
                    HON!PYTHON!PYTHON!PYT                   
                       PYTHON!PYTHON!P                      
                          ON!PYTHON                         
                             YTH                            
                              H


以上是关于用python打印各种图形的主要内容,如果未能解决你的问题,请参考以下文章

C语言打印图形

用c语言编写程序,打印以下图形。。 表示c语言老师讲的没听懂。。求大神。。。

java使用for循环输出图形 * *** ***** ******* ***** *** *

用shell或者python写出各种图形

怎样用Java代码打印并输出如下图形

Java如何用for循环实现以下图形 * *** ***** ******* ***** *** *