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 Basics Functions and Looping Functions

Euenlee Tan
Euenlee Tan
2,165 Points

Why can the number_of_characters variable be used again and again? Don't you have to use a diff term for diff 'advices'?

Each 'advice' had a variable called number_of_characters. If it was used the first time I get it, but when it was used the second time, wouldn't the program use the int obtained from len in the first 'advice'? Not sure if you get me.

2 Answers

Steven Parker
Steven Parker
231,236 Points

The line of code that uses "len" to set the "number_of_characters" comes right before the line that uses that value for the output. So for every message, these are both done, giving "number_of_characters" a fresh value.

If you could clarify this, I have the same question but was thrown off by the "result =" variable. Being that variables are immutable, I didn't think that it would print more than one variation of the result variable. Is there something about using a variable in a certain way that actually makes it reference something else? Is this an order of operations kind of thing?

Thanks!