Learn String Manipulation by Building a Cipher - Step 70

Tell us what’s happening:

I’m confuse about this,I have tried this several times but still getting error and also have problem with the indentation too

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) % len(alphabet)

# 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 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/120.0.6099.119 Mobile/15E148 Safari/604.1

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 70

1 Like

Original code:

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

Your code:

What happened to index ?

I should type in the structure you have given on that side

Originally the code was: (index + offset)

You changed it to (offset * direction)

Where did the index variable go?

Should I create new variable called new_index and assign the offset * direction to it on what’ should I do? Please I’m confused

All you need to do is multiply offset by direction. You don’t have to delete anything or create new variables.

If you have a + b and you want to multiply b by c before calculating the sum, how do you do it?

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

Here is the original line again. Just modify it, as you already did. Just do not delete what’s there.

new_index = (offset * direction) % len(alphabet)

You correctly multiplied by direction but you deleted “index +”. Don’t remove it :+1:

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