Python “while” loops, and how they kill me

I’m trying to solve for this code. Any Suggestions?

The block of code below works as is.

Do not change the three lines of code below.

users_inputted_password = input()
recommended_replacement_password = “”
i = 0

Refer to the requirements when editing the code below.

Replace every instance of YOUR-CODE-HERE in the lines below.

while i < len(YOUR-CODE-HERE):
if users_inputted_password[i] == “i”:
recommended_replacement_password += “1”
elif users_inputted_password[i] == “a”:
recommended_replacement_password += “@”
elif users_inputted_password[i] == “m”:
recommended_replacement_password += “M”
elif users_inputted_password[i] == “B”:
recommended_replacement_password += “8”
elif users_inputted_password[i] == “s”:
recommended_replacement_password += “$”
else:
YOUR-CODE-HERE += YOUR-CODE-HERE[i]
i = i + 1

recommended_replacement_password = YOUR-CODE-HERE + “!”

print (YOUR-CODE-HERE)

Hello, and welcome.

Python has semantic indentation, so it’s hard for a human to tell what your code is doing without the leading spaces and impossible to actually run it. Please edit your post to enclose all of the code in a “preformatted text” block, either by adding triple backticks (```) before and after the code, or by highlighting the code and clicking the formatting button that looks like </>. Please make sure the code looks the same in the editor where you wrote your code as it does in the preview pane here (possibly re-pasting it here if need be).

It will also be easier to help if you can provide examples of what you’ve tried that didn’t work, and how it didn’t work (gave the wrong output? exited with an exception? crashed with a segfault? caused your PC to halt and catch fire?)

With a little more information, I’m sure we can help you along your way (and probably also show you how to rewrite the whole thing in three lines while missing the point of the lesson :wink: )

1 Like