一元字符串的坏操作数类型 - 绘制图片时的str

时间:2014-01-26 18:12:35

标签: python python-3.x drawing operand

我正在尝试在我的计算机科学课上为家庭作业画一幅画。

#==================================
#Program Purpose: Drawing
#
# @Author: Morgan White
# @Version: January 26th, 2013
#==================================
print(                          -----         "Fancy Adventurer")
print(                         "l   l"            "-Morgan White")
print(                         "l   l")
print(                       "---------")
print("                         /   \ ")
print("                        / 0 0 \ ")
print("                       |   .   | ")
print("                        \  -  / ")
print("                         \---/ ")
print("                           | ")
print("                        ^^ | ^^ ")
print("                      /=========\ ")
print("                     /     |     \ ")
print("                    /      |      \ ")
print("                   /       |     |------| ")
print("               |  /        |     |      | ")
print("     <========]|={:}=      |     |      | ")          
print("               |          / \    |------| ")
print("                         /   \ ")
print("                        /     \ ")
print("                       /       \ ")
print("                      /         \ ")

我说错误

  

一元字符串的坏操作数类型 - :str

我做错了什么?

1 个答案:

答案 0 :(得分:0)

应该是

print("                          -----         \"Fancy Adventurer\"")
print("                          -----         \"Fancy Adventurer\"")
print("                         l   l            \"-Morgan White\"")
print("                         l   l")
print("                       ---------")

您应该将字符串传递给print,然后将双引号"放在要打印的内容上。如果你想在字符串中添加双引号,你必须使用\来转义它。像这样:\"。此外,如果您要将\添加到字符串,则必须使用\转义\,例如\\。比如r

要避免转义,请在r"之类的起始双引号之前添加print(" ----- \"Fancy Adventurer\"") print(" \"l l\" \"-Morgan White\"") print(" \"l l\"") print(" \"---------\"") print(r" / \ ") print(r" / 0 0 \ ") print(r" | . | ") print(r" \ - / ") print(r" \---/ ") print(r" | ") print(r" ^^ | ^^ ") print(r" /=========\ ") print(r" / | \ ") print(r" / | \ ") print(r" / | |------| ") print(r" | / | | | ") print(r" <========]|={:}= | | | ") print(r" | / \ |------| ") print(r" / \ ") print(r" / \ ") print(r" / \ ") print(r" / \ ")

因此这可行:

{{1}}