Learn String Manipulation by Building a Cipher - Step 50

Tell us what’s happening:

I have no idea how I am supposed to use proper indentation here. I have read some articles and watched a few videos and still don’t see where my indentation is incorrect.

Any advice helps.

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/121.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 50

Here’s how to indent a for loop:

for this in that:
    do this
    do this

and if statement:

if this == True:
    do that
else:
    do this

an if in a for:

for this in that:
    if this == True:
        do that
    else:
        do this

A function:

def function():
    this is inside the function
    this is inside the function
    this is inside the function
    this is inside the function

this is outside the function

All together:

def function():
    this is inside the function
    for this in that:
        if this == True:
            do that
        else:
            do this
    this is inside the function

this is outside the function

Hi @LowVel0city

The code under the if and else statements are not indented.

The last print call also needs indentatation.

I’d reset the step, add the function declaration, then indent every line below that by four spaces.

Happy coding

1 Like

These examples are extremely helpful, although they cannot be applied to step 50. I am being asked to define a function called caesar, but there is no code that goes in that function… so how am I supposed to do proper indentation if there is no code below my defined function?

I’ve reset my lesson, and added the defined function. I have tried indented all types of scenarios below the defined function. I can’t figure this one out, not unless the defined code has some type of code, which they don’t ask me to do.

Going off your above samples, there should be no indentation after my defined function because everything after my defined function is outside of the function.

week 2 of being stuck on step 50 lol…

Hi @LowVel0city

For this step you are placing the following code into the new function.
So, after declaring the function, indent all the following lines.


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)

By jove this worked. Bless your soul.

1 Like

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