Learn String Manipulation by Building a Cipher - Step 80

Tell us what’s happening:

what is wrong here, I did exactly as told

Your code so far

text = 'Hello Zaira!'
custom_key = 'python'

def vigenere(message, key, direction=1):
    key_index = 0
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    final_message = ''

    for char in message.lower():

# User Editable Region

        # Append space to the message
        if <.isalpha(char)>
            final_message += char

# User Editable Region

        else:        
            # Find the right key character to encode/decode
            key_char = key[key_index % len(key)]
            key_index += 1

            # Define the offset and the encrypted/decrypted letter
            offset = alphabet.index(key_char)
            index = alphabet.find(char)
            new_index = (index + offset*direction) % len(alphabet)
            final_message += alphabet[new_index]
    
    return final_message
    
encryption = vigenere(text, custom_key)
print(encryption)
decryption = vigenere(encryption, custom_key, -1)
print(decryption)

Your browser information:

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 80

Hi @Soul1,

We want to call the .isalpha() method on char. When we call a method on something, it’ll look like the following:

something.method()

isalpha() will return a boolean. The something.isalpha() would be the condition itself.

I hope that helps. Happy coding!

So I should remove if and write char.isalpha() only

Read the error message. It has a ^ showing you were the error is and it’s telling you exactly what is missing.

It shows Indentation error, what problem do I have, I have indented it four spaces after the for loop

Remember to use a : before an indentation.
Remember to indent any code that is to be executed inside of the if statement

example of an if statement
(this is an example not the answer)

if condition == True:
    #run this code


Like this

Please post your actual code instead of pictures

Ok, now that you have a condition, char.isalpha(), that will evaluate to true or false, remember to follow the syntax and indention for the if statement.

if condition: 
    x += y

Almost there. Happy Coding!

Please post your current full code (not a picture)

How do i post the code

Thank you I got it, I found the correct indentation and finished it

1 Like

You use copy and paste, and you use the code formatting tool.


When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

But writing the code all over is very much difficult and time consuming

You dont have to rewrite any code to post code, just copy and past the section between three backtics above and bellow

Here is an example:

#copy and pasted code without solution
# Append space to the message
        if char == ' ':
            final_message += char

This way people can copy and past your code into the task to see if they can see where things are going wrong.

With screen shots, people who want to help, must type out your code to test it. Which they wont always be willing to do.

thanks for telling me about this and why it is important, from next time I will make sure of it

1 Like