Learn String Manipulation by Building a Cipher - Step 90

Tell us what’s happening:

Step 90
Below the print() call you just added, add another print() call to print Key: python by concatenating the string 'Key: ’ and the value of the custom_key variable.

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

print('Encrypted text: ' + text)
print('key: python',('key:'+custom_key))

# User Editable Region

#decryption = decrypt(encryption, custom_key)
#print(decryption)

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/18.4 Safari/605.1.15

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 90

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

print(‘key: python’,(‘key:’+custom_key))
Error in this line

Ok. Can you say more? How do you know there is an error? What have you tried to fix it?

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)
print('Encrypted text: ' + text)

After this code its asking that question

#decryption = decrypt(encryption, custom_key)
#print(decryption)

Just posting code doesn’t really answer my question?

You should have a print() call that prints Key: python by concatenating the string 'Key: ' and the value of the custom_key variable.

That doesn’t answer my question either.

How do you know something is wrong with that line?

What have you tried to fix that line?

Please reply in your own words.

I tried to call the print function by concaneting key: and custom_key but the console in freecode camp course shows that message

Did you double check that every letter in the text you are trying to print is exactly as requested? Capitalization matters to the tests.

Thanks it is resolved.

1 Like

I am wrting to use f string but its showing error

I don’t know what that means? This step isn’t about f strings?

For example, you can get the same result of 'Encrypted text: ' + text with f'Encrypted text: {text}'. You need to put an fbefore the quotes to create the f-string and write the variables or expressions you want to interpolate between curly braces.

Modify the first print() call to use an f-string.

I need to modify this line
Print(’ Encrypted text:'+text)
To set same resukt with f string

This looks like a different step. If so, please open a new topic for that step.