Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Need help please!

For each of these messages, if the message is less than or equal to 140 characters, print the message; if it is longer than 140 characters, don't print it.

Add your code below the existing code, starting on line 4.

My code:

message1 = "The Analytical Engine weaves algebraic patterns, just as the Jacquard loom weaves flowers and leaves. -- Ada Lovelace, the first programmer"
message2 = "Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal."
message3 = "They told me computers could only do arithmetic. -- Computer pioneer Grace Hopper"
# Answer.......
if message1 <= message2:
    print("Print it")
else:
    print("Don't print it")
if message1 <= message3:
    print("Print it")
else:
    print("Don't print it")

The code gets printed, but i can't figure out were to put "len"? Error message reads:

Oops, try again. Use the len function to check the length of a string. Please help!!

Steven Parker
Steven Parker
243,318 Points

Please provide a link to the challenge to facilitate testing.

And when posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

I've added highlighting to Jorge's question. I took the liberty of commenting out the "Answer....." line. I assume that's not actually in his code, since it would obviously cause a compiler error. Jorge, if that is in your code, you'll want to delete or comment it out.

1 Answer

Steven Parker
Steven Parker
243,318 Points

Even without proper formatting, I can see that this code compares the messages with each other, but the instructions say that the message length should be compared with 140.

Also, when the condition is met, the instructions say to print the message, not the words "Print it". If the instructions ever ask you to print something specific, it will be shown in quotes.