Scientific computing with python

text = 'Hello Zaira'
custom_key = 'python'
def vigenere(message, key, direction):
    key_index = 0
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''
    new_index = offset * direction
    for char in message.lower():   
        # Append space to the message
        if char == ' ':
            encrypted_text += char
            # 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 = offset * key_index         
            encrypted_text += alphabet[new_index]  
    return encrypted_text 
#encryption = vigenere(text, custom_key)

I am a new learner in this course and I have followed the step-by-step to level 70 and this level requires me to multiply the offset by the direction in the new_index assignment. I am confused as to where to write this assignment. Can someone help on this ?

please post again your code, indententation is really important and if you don’t show it we can’t see what’s wrong in your code

It should highlight the area to focus on.

You may multiply offset right where it is, you can edit this line.
Screenshot 2024-02-02 193601

I do not have a line as such. My line reads as in the recent new_index assignment.

new_index = offset * key_index

You should reset the step and try it again. Let us know if you have any other question about it?

You need to multiply offset and direction

Resetting prompts me to reset the whole lesson instead of this particular step

Don’t worry, it just resets that step (it may be aka lesson but it only resets the current step)

Thank you. I did reset but the code didn’t pass the stage
I did the following assignment in the 19th line of step 70:
new_index = offset * direction

You should not change the whole of new_index, all the rest of the code need to stay on that line

I got it right! offset * direction was done within the parenthesis

Thank you for the patience and great assistance. Indeed you made me not to give up. I got it using the line below
–solution removed

Very nice! Glad you got it. Do you feel the instructions were too vague in this case?

I’m just going to remove the solution code, however. We are trying to not have too much spoiler / solution code in the forum to help people figure it out on their own.

No it was fine, It helped me think harder and for many days. This will make me to not forget this incident again.

1 Like