Learn String Manipulation by Building a Cipher - Step 43

Tell us what’s happening:

Could someone explain how this works? I got the right answer, but I’m not understand why it’s right, im so stupid

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 += char
    else:
        index = alphabet.find(char)
        new_index = index + shift
        encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)
    

# User Editable Region

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 43

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

Which part don’t you understand?

What line of code there are you not understanding? And what about it don’t you understand?

Please go back to Step #23 where the for loop is introduced. Re-read this lesson.

On the highlighted line in the editor, write:

for i in text:
    print(i)

Look at what is printed in the console.

Now do you understand what a for loop does?

I strongly recommend you learn from this Python curriculum. It is newer and prepares you better by providing theory lectures, workshops, and labs to help you learn.

You are not stupid. You are trying to learn, and that’s pretty smart! Keep at it. Take it a step at a time.

Do you have a question about how the for loop works? I’m happy to help if I can, but I need you to try to explain what it is that you are not understanding.

Python For Loops

programmers spend a lot of time trying to figure out stupid things

the only difference between an experienced programmer and a beginner is that the experienced programmer continued programming after getting blocked by “stupid” issues

you can find this meme in so many ways

so if you want to continue programming, this will happen again, and the only way to continue is to just continue after each block, bigger or smaller

failure is part of daily life for programmers, they just keep going

1 Like

if that’s what you want to do you are free to go this direction

but finding things hard is part of programming, and then you understand that, and then find a new hard thing later, the important part is not stopping

This forum is not equipped to deal with mental health issues, please search for professional support. If your life is in danger, please reach out to a hotline available in your country Suicide Hotlines - Suicide.org! Suicide Hotlines - Suicide.org! Suicide Hotlines - Suicide.org!.

i’m so sorry, i know, im so sorry

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.