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 (Retired) Things That Count Exceptions

Last example

When you entered .75, it should round off to the 4th out of 5 letters. But yours showed the 5th letter because user_string[4] obviously shows the 5th letter. Which is not what you want, is it? The index should be user_string[ratio-1]?

2 Answers

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Be careful not to confuse the index value with the count position. The value indeed rounds off to 4, but in the code it rounds off to index 4, not the 4th character. Index 4 is the 5th character.

Inspecting the code, the string offset is given by:

user_string = "Magic"
ratio = round(len(user_string)*our_num)

ratio = round(5 * 0.75)
ratio = round(3.75)
ratio = 4

The element at index 4, user_string[4], is "c".

Sorry if I'm remembering wrong, but didn't you want to pick out the letter that was closest to 75% "into" the word? Which would be the "i", no? That's why I was thinking you wanted the 4th character, or index 3 (ratio-1)

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

I agree the language Kenneth Love uses could be interpreted as not matching exactly with the results. Does he truly want the character 75% from the begin of the word (which agree is the 4th character "i"), or does he want the character reached using "0.75" on a zero-based count? The transcript says "And I want the number that is 75% of the way through. And that's the c." It leaves room for fuzzy interpretation.

My original answer was based on matching the code Kenneth used in the video. From a general spec viewpoint, I can see how wanting the character 75% of the way through could easily be interpreted as wanting the "i".