2012-12-01 98 views
1

我想提出一个刽子手程序ASCII艺术, 如何将我的蟒蛇 技术人员无需在每行上输入 打印有一个多行打印 像他们多行注释? 我不介意从文本文件中导入所有图片 ,无法从 的文档中弄清楚这一点,感谢您的帮助。包括蟒蛇

 def visual(): 
      if count = 1: 
       ## shows the hanging ascii art 

`

  ***************             
      *    *             
      *    *             
      *    *             
      *    *             
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
      *                
    ***********************             

一个错误

 ***************             
     *    *             
     *    *             
     *    *             
     *   ....            
     *   . ..            
     *   .. .            
     *   .. .            
     *   .....            
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                

两种错误的做法

 ***************             
     *    *             
     *    *             
     *    *             
     *   ....            
     *   . ..            
     *   .. .            
     *   .. .            
     *   .....            
     *    .             
     *  .......             
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                

`

回答

10

使用'''"""triple-quoted string literal

longstring = """\ 
You can use multiple lines 
and newlines 
are preserved 
""" 

我用开特里普尔引号后\换行符逃生,以避免把第一行打开引号之后。该字符串由此开始于You(之前没有换行):

>>> longstring = """\ 
... You can use multiple lines 
... and newlines 
... are preserved 
... """ 
>>> print longstring 
You can use multiple lines 
and newlines 
are preserved 
1

“像他们可以拥有多行注释”:有没有多行注释,只有多行字符串,当然你可以打印出来:

wrong_art[2] = """ 
     ***************             
     *    *             
     *    *             
     *    *             
     *   ....            
     *   . ..            
     *   .. .            
     *   .. .            
     *   .....            
     *    .             
     *  .......             
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *                
     *     
""" 

print wrong_art[num_wrong] 
+0

'wrong_art = [] –