Learn String Manipulation by Building a Cipher - Step 67

Tell us what’s happening:

What’s wrong with this code I think they might be a system error here there’s nothing wrong with this code?

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():
    
        # Append space to the message
        if char == ' ':
            encrypted_text += char
        else:        
            # Find the right key character to encode
            key_char = key[key_index % len(key)]
            key_index += 1

# User Editable Region

            def encrypt(text, shift):
    alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    encrypted_text = ""
    
    for char in text:
        if char.upper() in alphabet:
            is_upper = char.isupper()
            char_upper = char.upper()
            
            # Define the offset and the encrypted letter
            offset = shift
            index = alphabet.find(char_upper)
            new_index = (index + offset) % len(alphabet)
            
            if is_upper:
                encrypted_text += alphabet[new_index]
            else:
                encrypted_text += alphabet[new_index].lower()
        else:
            encrypted_text += char
    
    return encrypted_text
    pass


# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 67

this is not correct indentation, also why are you creating an encrypt function?

in your own words, what does this step asks from you?

It asks to remove the print functions then return encrypted text ok show me an example to tackle this task.

1 Like

you have an example of a return statement in the example code in the step

i also stuck here, in my case its not showing any identation error, but not able to go on next step

hi @itspraveen please create your own topic

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge. This button only appears if you have tried to submit an answer at least three times.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.