Learn String Manipulation by Building a Cipher - Step 84

Tell us what’s happening:

this is the instruction:
Below the line you just modified, add another print() call to print Key: python. Again, use concatenation (+) to get this result.

i stuck there:

how to do it i tried many different things and that were not working

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

print(‘key:’+custom_key)# I try that in this program

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

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: ' + text)
print('key:'+custom_key)
decryption = decrypt(encryption, custom_key)
print(decryption)

/* User Editable Region */

Your browser information:

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 84

please help me i am not able to do this

Don’t worry you will only get better. Let us follow the question step by step.

we are ask to use print() call to print Key: python and we are ask to use concatenation which involve the use of (+).

#Step 1 find the variable whose value is ‘python’ that variable is custom_key
#Step 2 concatenation: This is how you achieve it 'Key: ’ + custom_key
#Step 3: Pass it in your print() call hurray hurray hurray!!!

print('Key: ’ + custom_key)

1 Like

not working
i write print(‘key:’ + custom_key)

in the hint it say this :

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

what i need to do in program

check 2 things
First: Indentation .
Second: check if there is a space between Key and last quotation mark.

1 Like

the K should be uppercase

1 Like

It is not woking, what is wrong with it?

encryption = encrypt(text, custom_key)

print('Encrypted text: ’ + text)

print(‘Key:’ + custom_key)

decryption = decrypt(encryption, custom_key)

print(decryption)

hey there @Tarzan112345678 ! please open your own topic to ask for help!

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.