Learn String Manipulation by Building a Cipher - Step 75

Tell us what’s happening:

I modified the line:
if char.isalpha() == ’ ':

if not char.isalpha():

My code is working in the console but it’s still not passing the step.
This is my first time using freeCodeCamp and I’m not finding the tips very helpful at all. I understand the need to search for answers, but these are the very basics of a new topic and I find it’s not doing a good job at teaching me what to do nor teaching me what I did wrong.

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 not char.isalpha():
            final_message += char

/* User Editable Region */

            # 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)
decryption = vigenere(encryption, custom_key, -1)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 75

Hey, I know this might seem counterintuitive if you understand what you are doing. The hint suggests that the condition should be char.isalpha(). This is because the not operator has not been introduced yet. You will add it in a second moment. Hope this is helpful.

1 Like

Thanks for the reply. The problem is I only know very little.
It’s counterintuitive because either I know too much and can’t pass, or don’t know enough to understand the hints and can’t pass.

So right now it’s frustrating that I’d like to move on and continue learning, but I’m stuck here because I’m trying to think of the correct ‘wrong’ answer to give.

I tried:

if char.isalpha() == False

And that didn’t work either. I’m completely at a loss as to what FCC expects me to change the if statement to!

Modify the if condition by calling .isalpha() on char.

You’re very close. Sometimes, it helps to follow the instructions to the letter instead of trying to interpret the logic. You’ve done as instructed, but step doesn’t mention anything about checking if .isalpha() is False.

Hello marlon,

Don’t worry, as long as you keep your motivation you will keep learning. I am going to answer this question with your code from the first post in mind.

As the question describes: .isalpha() method returns True if all the character of the string on which it is called are letters. Meaning that if you did 'freeCodeCamp'.isalpha() it would return. Therefore if you had an if statement as followed:

if 'freeCodeCamp'.isalpha():
    print ('It worked!')

It would print the text because every character in the string is a letter.

Back to the question, ignore the comment that is above the code. We’re only going to change the if statement to see if .isalpha() on char returns True or not.

Finally got it.

Thanks for your help!
It’s difficult to stay motivated when things get frustrating like the minutiae of the site.


That’s understandable, but we’re all here for you during those times! :blush:

1 Like

You’re not alone! It’s frustrating as hell but that’s what makes the struggle beautiful when we succeed. Carry on the good work boss!

1 Like