Learn String Manipulation by Building a Cipher - Step 62

Tell us what’s happening:

Im uncertain if the code is correct here, any suggestions? its giving me errors

Your code so far


text = 'Hello Zaira'
custom_key = 'python'

def vigenere(message, key):
    key_index = 0
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

    for char in message.lower():

# User Editable Region

        # Append space to the message
        if char == ' ':
            encrypted_text += char
        else: 
             key_char = key[key_index % len(key)], key_index += 1

# User Editable Region

            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
    print('plain text:', message)
    print('encrypted text:', encrypted_text)

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 62

What error are you getting? This should indicate where your error is

You have inconsistent indentation here:

Screenshot 2024-05-13 084305

still doesnt pass the code

Please share your updated code and any errors you are getting, thanks!

Append space to the message

    if char == ' ':
        encrypted_text += char
    else: 
     key_char = key[key_index % len(key)], key_index += 1

Im getting a syntax error

You still have inconsistent indentation

Screenshot 2024-05-13 103401

When you indent keep everything the same. Four spaces, or just press tab once. The line below if and the line below else need to be indented the same amount. They need to have exactly the same amount of spaces.

    # Append space to the message
    if char == ' ':
        encrypted_text += char
    else:
       key_char = key[key_index % len(key)], key_index += 1

am i still doing it wrong…?

yes, it’s still wrong

if this:
    code code
else:
    code code

Just indent these lines the same amount of spaces

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