Learn String Manipulation by Building a Cipher - Step 70

Tell us what’s happening:

I am unable to input my code in the place above it is not accepting my input can someone help me in this?

Your code so far


# User Editable Region

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

            # 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)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 70

Hi there! :waving_hand:

The lesson asked you to:

  1. Add a third parameter called direction to your function definition.
  2. Comment out the last two lines of your code to avoid errors in the console.

It looks like you missed both points. Here’s how to fix it:

[solution removed by moderator ]

This should solve the issue! Let me know if you need further assistance! :blush:

1 Like

Thanks for the guidance i have followed your first step but unable to implement the second one can you show it with a pic it would be much more helpful

We can’t give the answer but we can guide you. Where are your function parameters?

Hi. I’ve removed the solution. We focus on guiding rather than giving the answer.

1 Like

It seems you’ve already implemented the first step, which is great! To help with the second:

  • To comment out the last two lines, you can simply add a # symbol at the beginning of the lines. This will tell Python to ignore those lines when running the program.

If you need further clarification on the second step, feel free to ask. Happy coding!

But I just explained how to fix it without giving the complete solution, so is it still not allowed?

Rule 13 says:


Do not simply hand someone the solution to their problem. In doing so, you deprive them of the learning process. Instead, consider guiding them to reach the solution on their own

An example syntax of a comment would have been better in my view.

Here is the article linked to on how to guide: How to Help Someone with Their Code Using the Socratic Method

1 Like

ok my bad again i have implemented the second step but unable to implement the first direction step can you help me in which step should i put that direction code line?

Let’s revisit the lesson instruction:

“Add a third parameter called direction to your function definition.”

Can you take a moment to look at your function — how many parameters does it currently have? :thinking:
Where in your code could you add that third parameter?

Give it a try and let me know what you discover! Happy to help if you get stuck again.

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)
This is the code and i am not getting in which step do you want me to add this direction i am not getting the third parameter in the code can you please help me?

oh got it thanks for the help seoexpert

You’re very welcome! :blush:
I’m glad I could help you out. Keep up the great work, and if you ever need more assistance, feel free to reach out here in the forum, we’re always happy to help! :flexed_biceps:

1 Like

i am getting the error in step 71 even after typing the right input it says to multiply offset with direction in the new index but it is not accepting my input can you help me in that?

For better organization and to keep each step clear, please consider creating a new topic for the next challenge step.

as you have finished with step 70 I am closing this topic, step 71 needs a different topic