I’m confused about when to use range() and when to use len() in these exercises. Can someone explain why this is wrong, for the first step in the exercise? I’m reasonably sure it has something to do with the steps where I use “range” but I don’t know why or how to fix it.
Also, can anyone tell me how to indent, in these replies/questions? Not being able to indent is making me crazy.
The way this exercise wants you to complete it is quite complicated. I was able to write both functions using only 6 lines of code. In my code I’ve used f-strings (which haven’t been introduced yet), but it could be accomplished just as easily with string concatenation.
user_name can only be accessed inside the function username_generator which is local scope unless you declared a variable user_name in the global scope which is outside of the functions!
Hi! I found your solutions very helpful! However, I didn’t quite understand how the password_generator() works and output the letters shifted to the right. Could you please explain a bit? Thanks!
Since the loop is “i in range(length of username)”, the very first i would be 0. The goal is to use the last letter as the first letter, then the rest of the string in order.
So, the first iteration is i - 1, or 0 - 1, which is -1. The value -1 points to the last value of the index of a string or array. If I had the name “Steve” it would target the last “e” first. Then, we add 1 to i as the next part of the loop, making the new value 1 - 1, or 0, which is the S. This will loop until it finishes with eStev. It stops after 5 loops because len(“Steve”) = 5.
Thanks for the explanation! Much clear now. So I can deduce that password = "" will only contain 5 letters because len(“Steve”) = 5 and that’s when the loop stops, right? giving the "eStev" output.