Learn String Manipulation by Building a Cipher - Step 83

Tell us what’s happening:

I have been trying to get past this very simple code for hours now. I understand how to use concatenation using the ‘+’ operator. The code I am using works in PyCharm. I’ve tried using f-string instead but that is also rejected. No matter what I enter here it is always false when it really isn’t false, but maybe you are looking for some other answer.

Your code so far

text = 'mrttaqrhknsw ih puggrur'
custom_key = 'python'

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

    for char in message.lower():

        # Append any non-letter character to the message
        if not char.isalpha():
            final_message += char
        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

def encrypt(message, key):
    return vigenere(message, key)
    
def decrypt(message, key):
    return vigenere(message, key, -1)

# User Editable Region

encryption = encrypt(text, custom_key)
print('Encrypted text: ' + encryption)
decryption = decrypt(encryption, custom_key)
print(decryption)

# 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/119.0.0.0 Safari/537.36 Edg/119.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 83

Hello angerking,

The question says: " Use the + operator to concatenate text to your string". What you did is to concatenate encryption to your string. Do you see the difference?

Of course I see the difference and I have attempted all kinds of text concatenations, all of the answers below produce the desired output but are not acceptable.
print('Encrypted text: ’ + ‘mrttaqrhknsw ih puggrur’)
print('Encrypted ’ + 'text: ’ + ‘mrttaqrhknsw ih puggrur’)
print(‘Encrypted ’ + ‘text: mrttaqrhknsw ih puggrur’)
print(‘Encrypted text: mrttaqrhknsw ih puggrur’)
print(f’Encrypted text: {decryption}’)

It would be nice if one could just move on, I understand the material but just don’t grasp what exactly is being asked. This hurdle is not benefitting my learning it’s just keeping me from moving to the next lesson.

Edit: problem solved. You wanted the original string variable: text

I do understand the difference between the variables text and encryption, thanks for the tip! It did eventually lead me to understand my folly.

print('Encrypted text: ’ + text)

1 Like

This material is currently Beta. This question and many others are currently being re-written based on feedback like this.

1 Like

Your code is correct but you need print not encryption variable which is already encrypt original text but variable text
Solution Removed***

This was already resolved a week ago, and please don’t post solution code, thanks!

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.