Learn String Manipulation by Building a Cipher - Step 49

Tell us what’s happening:

what am im doing wrong, i forgot how to make indention

thanks

Your code so far


# User Editable Region

text = 'Hello Zaira'
shift = 3
def caesar():
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''
    
for char in text.lower():
    if char == ' ':
        encrypted_text += char
    else:
        index = alphabet.find(char)
        new_index = (index + shift) % len(alphabet)
        encrypted_text += alphabet[new_index]
print('plain text:', text)
print('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/131.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

to indent add spaces at the beginning of the line, you still need to indent the for loop and the print statements

sorry, how should i indent the for loop and print?

not to sure about the spacing for the code

strong text

text = 'Hello Zaira'
shift = 3
def caesar():
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

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

.

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 (').

1 Like

the for should be at the same level of encrypted_text, while the content of the loop should be indented 4 spaces more than that

alternatively, reset the step, add the function defition, then select everything that should go inside the function and press the tab key once

text = 'Hello Zaira'
shift = 3
def caesar():
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

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

hi, im still having trouble…

the two prints go inside the function too

1 Like