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

Python Function - this is racking my head!

Why does the console not return "YOU ARE DOING GREAT!"

This isn't the first time this discrepancy has happened between code in the file browser and the console.

Code below.

praise = "You are doing great" praise = praise.upper() number_of_characters = len(praise) result = praise ÷ "!" + number_of_characters print(result)

Steven Parker
Steven Parker
243,253 Points

When posting code, use Markdown formatting to preserve the code's appearance and retain special symbols. An even better way to share code and make your issue easy to replicate is to make a snapshot of your workspace and post the link to it here.

1 Answer

Steven Parker
Steven Parker
243,253 Points

You have a "÷" symbol in the code, which is not a Python operator. I'm going to guess you meant to use a plus sign "+" there.

But you also cannot "add" a string to a number. You need to convert the number to a string to concatenate:

result = praise + "!" + str(number_of_characters)

The result will then be: "YOU ARE DOING GREAT!19"

But another possibility is that you meant to use "*" instead of "+" for the second operator:

result = praise + "!" * number_of_characters

The result would then be: "YOU ARE DOING GREAT!!!!!!!!!!!!!!!!!!!"

For future questions, in addition to formatting the code, always include a link to the course page so we can see what the objective is.