Im having trouble understanding where to “add the space” , and what does “currently stored in char” mean?
Your code so far
# User Editable Region
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
if char == (" "):
encrypted_text += (" ")
index = alphabet.find(char)
new_index = index + shift
encrypted_text += (alphabet[new_index])
print('char:', char, 'encrypted text:', encrypted_text)
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 42
First of all, don’t wrap the string inside the parentheses: (" ").
Just " " is correct.
Secondly,
The instruction asked us to:
use the addition assignment operator to add the space to the current value of encrypted_text.
So, what you did:
encrypted_text += " "
is correct.
BUT:
Let’s take a look at the if statement:
if char == " ":
encrypted_text += " "
The encrypted_text += " " expression only happen when char == " " right?
That means, at that time when the expression above happens, the value of char is " ".
That’s what " the space (currently stored in char)" mean.
So, instead of
use the addition assignment operator to add the space to the current value of encrypted_text
we can just
use the addition assignment operator to add char to the current value of encrypted_text
I’m dying inside from still not understanding this explanation. I completed it, but because I’m so confused on the why behind this lesson, I’m not wanting to move fwd yet. So far there is quite a few things along the way that, yes I got them right… but very unsettling why most of what I’m doing isn’t truly “clicking” yet.
Please open a new topic for your question and please refrain from commenting on 6 month old threads if there’s nothing new to add, thanks!
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge. This button only appears if you have tried to submit an answer at least three times.
The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.