Learn String Manipulation by Building a Cipher - Step 51

Tell us what’s happening:

I already called the function and tried multiple indentations. I believe the function should be at a new line.

Your code so far


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

def caesar()

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 51

1 Like

To call a function, it’s just the name of the function and brackets (and any arguments), you do not need to write “def”:

function()

def is to define a function, which you only need to do once. When the code of the function has been defined, you call the function and it will run that code in the definition

def caesar():
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''
    ....

Thank you so much. Aaaah this one got me good. I knew it was something simple. Thank you!

1 Like