The step 70 is not accepting my result/answer. Keeps failing to move to the next step without any obvious error.
it keeps saying, “Sorry, your code does not pass. Hang in there.”
This is the instruction: “You should change each occurrence of encrypted_text
into final_message
.”
I have done it in the right way but not accepting.
Please help me out. Cheers
text = 'Hello Zaira'
custom_key = 'python'
/* User Editable Region */
def vigenere(message, key, direction):
key_index = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
final_message = ''
for char in message.lower():
# Append space to the message
if char == ' ':
final_message += char
else:
# Find the right key character to encode
key_char = key[key_index % len(key)]
key_index += 1
# Define the offset and the final_message
offset = alphabet.index(key_char)
index = alphabet.find(char)
new_index = (index + offset*direction) % len(alphabet)
final_message += alphabet[new_index]
return final_message
/* User Editable Region */
encryption = vigenere(text, custom_key, 1)
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/120.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 70
Learn to Code — For Free
system
December 31, 2023, 4:56pm
2
You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.
Hello GreatSunny,
This actually took me a hot minute to find, so I understand the confusion. But you weren’t supposed to change the # Define the offset and the encrypted letter
comment.
1 Like
Thank you for your response but the error is still showing even after putting the comment back.
Can you help further please?
Yes of course!
Can you show how your code looks now?
If I copy your code, and pass the right comment back it passes for me, so just want to double check.
This is my code now:
text = ‘Hello Zaira’
custom_key = ‘python’
def vigenere(message, key, direction):
key_index = 0
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
final_message = ‘’
for char in message.lower():
# Append space to the message
if char == ' ':
final_message += char
else:
# Find the right key character to encode
key_char = key[key_index % len(key)]
key_index += 1
This is the exact text the comment should be:
# Define the offset and the encrypted letter
It’s very strict, and if you change it unfortunately even if your code is correct it won’t pass.
2 Likes
# Define the offset and the encrypted_text
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, 1)
print(encryption)
decryption = vigenere(encryption, custom_key, -1)
print(decryption)
It is still giving same error even though I just copied this comment and pasted it. I am done with other aspects of that section except the Step 70.
Try to reset the question so that everything is like it used to be again, and only replace the four encrypted_text
variables in the code to final_message
.
There should only be 4 changes.
5 Likes
Wowww!! You are superb HungryBee. Thank you.
4 Likes
Your code looks fine except the your comment, which changed
Define the offset and the final_message
however some time you need to reset the session or relaunch your browser,
many time I have the coded the right answer but keep giving me errors tell I restart my browser