Python

Moderators: None (Apply to moderate this forum)
Number of threads: 400
Number of posts: 1055

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Strings Posted by Garrett85 on 23 Sept 2009 at 9:30 AM
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 "<pyshell#14>", line 1, in -toplevel-
+ "\nBut what " + "you don't know," + " is that " + "it's one real" \
TypeError: bad operand type for unary +



# Silly Strings
# Demonstrates string concatenation and repetition


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

    + "\nBut 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?\n\n" + "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 "\nNow that's good eating."

raw_input("\n\nPress the enter key to exit.")

Report
Re: Strings Posted by c__D on 22 Dec 2009 at 5:48 PM
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:
# Silly Strings
# Demonstrates string concatenation and repetition


print "You can concatenate two " + "strings with the '+' operator." \
    + "\nBut 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?\n\n" + "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 "\nNow that's good eating."




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.