Learn String Manipulation by Building a Cipher - Step 41

Tell us what’s happening:

Well i am not sure what i am doing wrong… i checked the posts and tehr was nothing heplful and searched on youtube too but still no help.

i would someone to tell me whats wrong in this and help me as i am unable to figure it out from quite some time

Your code so far


# User Editable Region

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

for char in text.lower():
    if char == ' ':
        print('True')
    else:
        print('False')
    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/121.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 41

print the result of comparing char with a space (' ').

Here you make the correct comparison:

You just need to print that. For example if I was to print the result of adding a to b I would code:

print(a + b)

or I could print the result of other comparisons

print(a > b)
print(a != b)

you don’t need to create an if statement in this step, only print the comparison of char with a space using the comparison operator ==

  1. Check how you’re handling spaces in your loop.
  2. Ensure that your index calculation accounts for the shift and wraps around the alphabet if needed.
  3. Consider using the modulo operator to handle the wrapping around the alphabet.
  4. Make sure to append the encrypted character or space to the encrypted_text variable inside the loop.
  5. Test your code with different inputs to ensure it works as expected.

This is what I have, and it still DOESNT work . I already spent an hour on . the spaces are there as well. They should have an answer guide, to help figure out the problem.

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

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

ou should compare char with a space using the equality operator inside your for loop. You should print the result of comparing char with a space inside your
for loop. You should print the result of comparing char with a space at the beginning of your loop. // tests completed

Here is the difference between a “space” and an “empty string”. If you have any other questions, please open a new topic, thanks

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').