Learn String Manipulation by Building a Cipher - Step 70

Tell us what’s happening:

Describe your issue in detail here.

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 70

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

1 Like

i find a problem in the line of Step 70

All you need to do is multiply the offset by the direction in the new_index assignment. The multiplication operator in Python is *. i type
new_index = offset * direction
as I understand but the step in not submit

1 Like

Welcome to the forum @achraaf

Here is your code:

Here is the original code:

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

The aim for this step is to modify only a part of the code.
Multiply offset by direction, leaving the rest of the code intact.

Happy coding

thanks bro but it’s still not work

Please post your full code.

Use the following method to post code to the forum:

  1. On a separate line type three back ticks.
  2. On a separate line paste your code.
  3. On the last line type three back ticks. Here is a single back tick `

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)
        new_index = (index + offset) % len(alphabet)
        encrypted_text += alphabet[new_index]

return encrypted_text

#encryption = vigenere(text, custom_key)
#print(encryption)
this is my full code even when I try to fix the problem with your help it still can work and I don’t why so thanks for your help and please if you can find the source of problem because I try many times but without results

Hi @achraaf

Multiply offset by direction, without modifying the other code.

To be safe, first reset the step.

hi Teller
it’s still not working I reset the step 70 and I change the original line to thw new one " new_index = offset * direction "
but I have this notification " You should multiply offset by direction in the new_index assignment. Do not add other parentheses."

do not replace the whole line, you should add the multiplication by direction inside the existing expression

unfortunately still not working I delete only the expression of index and the sign + and the formule % len( alphabet) but it’s still not working and add " * direction " also I try to

what is your new code please?

I replace this " new_index = (index + offset) % len(alphabet) "
to this --solution removed--
that what tell me @Teller but I resolve now the problem thanks for your help @ILM and @Teller the solution is --solution removed-- if any one struggle in this step this is the solution

1 Like

Please don’t post solutions, thanks!

Although I already solved the problem, but I feel most of the hint of the solution in the question page(in the freeCodeCamp) really need to be redefine, it keep making people misunderstanding the requirements, especially for those english is not their main language.

if you have specific suggestions on the changes feel free to open an issue on github

1 Like