我在显示石头剪刀布的图像时遇到一些问题。我对 python 很陌生(3 周),我正在尝试打印多行“图像”。
请原谅我糟糕的艺术!
import random
def Display_Rock():
print ("""\n
_---___
/ .#.... \
/ .$../\.. \
|_________/
""")
def Display_Paper():
print ("""\n
__________
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|__________|
""")
def Display_Scissors():
print ("""\n
_----_
/ /--\ \
| \__/ \_________________
\____ \
/ ------------------\
/ /--\ _________________/
| \__/ /
\-____-/
""")
Display_Rock()
Display_Scissors()
Display_Paper()
这将显示以下内容 -
_---___
/ .#.... / .$../\.. |_________/
----_
/ /--\ \
| \__/ \_________________
\____ / ------------------ / /--\
_________________/
| \__/ /
\-____-/
__________
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|__________|
感谢您的阅读和提前提出的任何评论!
最佳答案
在字符串之前使用 r
,如下所示:
def Display_Rock():
print (r"""
_---___
/ .#.... \
/ .$../\.. \
|_________/
""")
>>> Display_Rock()
_---___
/ .#.... \
/ .$../\.. \
|_________/
Python 将您的 \
视为转义字符。
关于Python - 多行打印图像无法正确显示问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39668683/