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 += 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/122.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 43

Good day
I’m experiencing a syntax error on my code, I di make use of the additional assignment to add the value of char . Kindly assit me with this issue.

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.

Hello!

Your if statement needs a condition to check first.

In Python it’s for example

if variable == condition: 
         add thisthing to variable

Try to solve the task after this pattern. Remember we want to check if there’s a ' ' (space).

I’m required to replace print space with the addition assignment so what I did inside the if statement I declared the variable of char of which i assigned the value of encrypted_text which is ’ ', yet I’m still getting an error, I might not have understood the question so could you kindly explain in a less technical way so that I can get a better understanding.

This isn’t valid syntax for an if statement. How would you describe what it’s checking in words?

You need to reset the step, the instructions don’t ask you to change the if statement.

instead of printing 'space!',

You need to replace this line:

print('space!')

with this:

use the addition assignment operator to add the space (currently stored in char) to the current value of encrypted_text.

1 Like

Warm Welcome There !
I think this is a less technical solution :
The if char += encrypted_text : line is invalid according to Python. This will throw a Syntax Error.
Because, first understand that a if condition works when something returns True. In your code’s if condition, nothing is returned as True or False. The Python’s += operator is a operator that does a built - in function operator thing. It does something, not checks something.
Change the if condition to a better way to check if there is a space (" ") there.
Thanking You. Reply if you still have doubt.

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