Learn String Manipulation by Building a Cipher - Step 49

Tell us what’s happening:

Hi I’ve been at this step for so long
it keeps telling me I should use the def keyword to declare a new function. I thought Caesar was the keyword

Your code so far


# User Editable Region

text = 'Hello Zaira'
shift = 3
    def caesar(text, shift):
    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/124.0.0.0 Safari/537.36 Edg/124.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

remove the spaces from in front of the def keyword, you need to have no indentation for this line

Hi thanks for getting back to me. So I took the spaces away and now I get “You should add a pair of parentheses after the function name. Don’t forget the final colon”.

you are not asked to have any arguments, that may be why you get this error

hi @ilenia def caesar(): this is what i now have and this is what it now say " Your code has an indentation error. You may need to add pass on a new line to form a valid block of code."

You don’t need to add pass in this case, but you must indent all the lines of code after def caesar():

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)

Your code has an indentation error. You may need to add pass on a new line to form a valid block of code.

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

Your for loop and if statement are not correctly indented

It needs to be like this:

Mod Edit SOLUTION REMOVED

You can then call it like this:

caesar(text,shift)

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.