在python中包含ascii艺术

2024-05-14 11:26:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做一个刽子手计划, 我怎样才能在Python中包含我的艺术 不在每行打印 有多行打印吗 好像他们有多行评论? 我不介意把所有的照片都导入 从文本文件中,无法从 文档,谢谢你的帮助。

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

`

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

一个错误

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

两个错误

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

`


Tags: the文档ifdefcount错误评论艺术
2条回答

“like they can have multi line comments”:没有多行注释,只有多行字符串,当然您可以打印它们:

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

print wrong_art[num_wrong]

使用'''"""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

相关问题 更多 >

    热门问题