Learn String Manipulation by Building a Cipher - Step 43

Tell us what’s happening:

I do not know what to put in else statement so that the program does not put c for the space. What should I fill my else with? Thanks guys

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:
        encrypted_text 
    print()
    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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 43

“To fix it, add an else clause after encrypted_text += char and indent all the subsequent lines of code except the print() call”.

What in your code do you see that doesn’t match up with the instructions?

I kinda got it. But what else should I add to else?

indent all the subsequent lines of code except the print() call.

Indenting the lines of code after else: will make them part of the else block of code.

You’ve added a print() line you can remove it, or reset the step.

1 Like

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