Learn String Manipulation by Building a Cipher - Step 70

Tell us what’s happening:

I had modify the line new_index = (index + offset) % len(alphabet) to new_index = offset * direction but when I try to validate, I have this error message : Sorry, your code does not pass. You're getting there. and I don’t understand why because I done exactly what is asked. Can you help me ?

Your code so far

text = 'Hello Zaira'
custom_key = 'python'

def vigenere(message, key, direction):
    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

            # Define the offset and the encrypted letter
            offset = alphabet.index(key_char)
            index = alphabet.find(char)

# User Editable Region

            new_index = offset * direction

# User Editable Region

            encrypted_text += alphabet[new_index]
    
    return encrypted_text
    
#encryption = vigenere(text, custom_key)
#print(encryption)

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 OPR/107.0.0.0 (Edition std-1)

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 70

1 Like

Hi there. You seem to have deleted some of the seed text provided in the challenge. That is probably why your code doesn’t pass. Hit the reset button and then only multiply offset by direction.

Happy coding.

1 Like

I already tried to reset and it still doesn’t work.

1 Like

Please show me your updated code.

it’s the same as above

This is what you start with.

new_index = (index + offset) % len(alphabet)

In the challenge, you have to multiply offset by direction. That is the only change required.

Yeah this is what I start with. So I modified this line with new_index = offset * direction (because that’s what I have to do) but that’s don’t confirm the test and I don’t understand why

Don’t delete the rest of the code from the line, just add the multiplication. You still need the modulo.

Okay I understand my fault. But the statement misled me

you should reset the step and then edit the line by multiplying offset and direction inside the first parenthesis in new_index variable it would be like this:
(index + offset * direction)
please, don’t delete anything from the code, only add the *direction

1 Like