Question

I am trying to draw a picture for a homework in my computer science class.

#==================================
#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("                      /         \ ")

I have an error saying

bad operand type for unary string -:str

What am I doing wrong?

Was it helpful?

Solution

It should be

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

You should pass a string to print and you do that by putting doublequotes " around what you want to print. And if you want to add doublequotes inside the string you will have to escape it with a \ e.g. like this: \". Furthermore if you want to add \ to the string you will have to escape \ with \ e.g. like \\

To avoid the escape add an r before the starting double-quote like r".

Hence this would work:

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"                      /         \ ")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top