Learn String Manipulation by Building a Cipher - Step 43

Tell us what’s happening:

Describe your issue in detail here.

Your code so far


# User Editable Region

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''

for char in text.lower():
    if char == ' ':
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text += alphabet[new_index], 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/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 43

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

invalid code, why have you added , char to this line? what is it that you want to do?

the instruction is Now, instead of printing 'space!' , use the addition assignment operator to add the space (currently stored in char ) to the current value of encrypted_text .

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''

for char in text.lower():
    if char == ' ':
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text += alphabet[new_index]
        print('char:', char, 'encrypted text:', encrypted_text)

he instruction is Now, instead of printing 'space!' , use the addition assignment operator to add the space (currently stored in char ) to the current value of encrypted_text .

text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
encrypted_text = ‘’

for char in text.lower():
if char == ’ ':
index = alphabet.find(char)
new_index = index + shift
encrypted_text += alphabet[new_index]
print(‘char:’, char, ‘encrypted text:’, encrypted_text)

you have an if statement but nothing inside it, you want to add char to encrypted_text here

You should use the += operator to add char to the current value of encrypted_text inside your new if statement.

I tried. I don’t know what is wrong. Honestly this is my first day here. Prior I finished just Mimo app in a week so I have zero qualification so far I’m just interested

Hello!

It’s actually very simple:

  • Reset the exercise
  • Remove the print function
  • Take encrypted_text and add encrypted_text + char (solve this using the addition assignment +=)

As always in Python use the right indention.

If you are new to coding here is a hint:

An addition assignment like += shortens your code, so you don’t have write one item twice.

So a += b instead of a = a + b.

1 Like

thank you! yes I’m very new. I memorized these, however the correct indention is the one always gets me. I will try tomorrow thank you again.

Now, instead of printing 'space!' , use the addition assignment operator to add the space (currently stored in char ) to the current value of 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)

please help stuck on this one

Please open a new topic for your question

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 Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for 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.

Thank you.

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