2012-12-01 96 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 = [] –