Strings - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Strings

Garrett85Garrett85 Posts: 168Member
I can't find the error in the following code, can someone help me out please? I really don't like this python IDE, is there a better one I can use?

Here is the error message I'M getting.
Traceback (most recent call last):
File "", line 1, in -toplevel-
+ "
But what " + "you don't know," + " is that " + "it's one real"
TypeError: bad operand type for unary +



[code]# Silly Strings
# Demonstrates string concatenation and repetition


print "You can concatenate two " + "strings with the '+' operator."

+ "
But what " + "you don't know," + " is that " + "it's one real"
+ "l" + "y" + " long string, created from the concatenation "
+ "of " + "thirty-two " + "different strings, broken across "
+ "nice lines." + " Now you are" + " impressed?

" + "See, "
+ "even newlines can be embedded into a single string, making"
+ " it look " + "as " + "if " + "it" + "'s " + "got " + "to "
+ "be" + " multiple strings." + " Okay, now this " + "one "
+ "long" + "string " + "is over!"

print
"""
If you really like a string, you can repeat it. For example, who doesn't
like pie? That's right, nobody. But if you really like it, you should
say it liek you mean it:""",

print "Pie" * 10

print "
Now that's good eating."

raw_input("

Press the enter key to exit.")[/code]

Comments

  • c__Dc__D Posts: 2Member
    I have no idea why u were having problems with that, in python 2.5 it does well and it should do also in 2.6. in IDLE it says there is an unindented block...
    WATCH YOUR SYNTAX!!!

    working code:
    [code]# Silly Strings
    # Demonstrates string concatenation and repetition


    print "You can concatenate two " + "strings with the '+' operator."
    + "
    But what " + "you don't know," + " is that " + "it's one real"
    + "l" + "y" + " long string, created from the concatenation "
    + "of " + "thirty-two " + "different strings, broken across "
    + "nice lines." + " Now you are" + " impressed?

    " + "See, "
    + "even newlines can be embedded into a single string, making"
    + " it look " + "as " + "if " + "it" + "'s " + "got " + "to "
    + "be" + " multiple strings." + " Okay, now this " + "one "
    + "long" + "string " + "is over!"

    print
    """
    If you really like a string, you can repeat it. For example, who doesn't
    like pie? That's right, nobody. But if you really like it, you should
    say it liek you mean it:""",

    print "Pie" * 10

    print "
    Now that's good eating."[/code]
Sign In or Register to comment.