Learn String Manipulation by Building a Cipher - Step 38

Tell us what’s happening:

Describe your issue in detail here.
it keeps telling me to delete print(char == " " when i already did and replaced it with an if statement

Your code so far


/* User Editable Region */

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
    if (char == "space!")
    
    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/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 38

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.

Your IF statement is missing something:

https://www.w3schools.com/python/gloss_python_if_statement.asp

Example:

if b > a:
  print("b is greater than a. This is the IF body.")

You are to compare char to “an empty space” which is a space between two quotes, the same as the evaluation in the original print: print(char == ' ')

It’s also missing this part:

Inside the if body, print the string space!. Remember to indent this line.

1 Like

alright i think i did what you told me but its still wrong

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
    if char == " " :
     print("space!")
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)

It looks like your if statement is now correct. Can you show us the code using the code format like you did in the first post? We can’t see if you indented the code right otherwise.

I edited this to show your code clearly (you can embed code in triple backticks, or use the code button the menu, it looks like this </>

Agree with @HungryBee I would check that indentation

i don’t understand aren’t backticks just these ’ ? or am i missing something

He changed your second post so we can see the code formatting.

Did you get the step to work? If not I would try and reset the step and do it again to make sure you didn’t accidently change anything else that you didn’t notice. (I’ve been there as well haha).

Backtick shares a key with tilde ~. It’s the other character on there `

thanks for the help guys i really was struggling on that :smiley:

2 Likes