Confused with mashing up strings and functions and indices

I need help please with the Review question #2 at the end of the Python 3: Introduction to Strings lesson. See link below …

https://www.codecademy.com/courses/learn-python-3/lessons/introduction-to-strings/exercises/review-i

My code looks completely different to the “View solution” code provided by Codecademy. BUT my output produced the correct order of characters! Here’s a screenshot of my code vs Codecademy’s solution code side by side …

And here is the scary you-are-wrong message that I got when I ran my code …

Can someone please explain, uh … I mean, I can obviously see where my code differs from the Codecademy solution, but, uh … I am baffled enough to not even know what to ask or where to ask for help in my thinking.

Replying to myself.

  1. I set my password = which would output a list of characters separated by commas … as seen in the scary you-are-wrong message. I actually needed to output a string … that’s why the correct code is password = ‘’ with the quotes.

  2. And because you’re supposed to set password to output a string (denoted by the quotes), I cannot used .append(). The only way to add to a string is with a += operator (as seen in the correct code).

  3. The index 0 needs to be specified (which I failed to do in my code) because the instructions said that the first character in the password would be the last character in the username. So the combination of the index 0 and the code [index -1] addresses this.

Am I understanding this all correctly? So much to keep track of and to think about.

the built in function, range has 3 parameters: range(start, stop, step) the 3rd parameter, is optional. As you have it, you have one parameter, len. So, what happens when you add the 0 index?
ie:

for i in range(0, len(user_name)):

See:

Also, password should be set to an empty string, not an empty list. And don’t use .append

Thanks lisalisaj for your reply. I read the Python documentation on range that you referred me to. I am not understanding the statement that I underlined in red. See below …

In my original code, I didn’t include the 0 index in the start argument. The statement that I underlined in red seems to support my original code … that writing out the 0 index wasn’t necessary because leaving it empty (omitting it) would have defaulted the value to 0?

point taken.

The question’s directions asks that password is set to an empty string, not a list of letters (as you have it). So, after re-reading the reply to yourself–(and the last sentence in my reply)–yes, those three points are correct.