Tell us what’s happening:
I don’t now the coding error.
Somebody can help me?
Your code so far
# User Editable Region
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
index = alphabet.find(char)
new_index = index + shift
if char == " ":
encrypted_text += "c"
else:
encrypted_text += char
print('char:', char, 'encrypted text:', encrypted_text)
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 43
Reset the step and try again, you made more changes than the instructions asked
add an else
clause after encrypted_text += char
and indent all the subsequent lines of code except the print()
call.
How did you end up with this?
encrypted_text += "c"
I agree I don’t know where you got the syntax mentioned in the above comment, other than that after a while I figured it out, and it is simply to make the “else” statement inline with where the “if” statement begins and then indent the next three lines (except the print() function at the end) within the “else” statement. Like this:
–removed–
You see how the, “if” and “else” statements are inline. What I now understand is that the “else” statement is a decedent of the “for” loop and not the “if” statement, which is why the “else” statement should be inline with the “if” statement. Note that both of the statements are simply decedents of the “for” loop. This should get you the right answer. Good luck!!
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
1 Like