Step 71
All you need to do is multiply the offset
by the direction
in the new_index
assignment. The multiplication operator in Python is *
.
(this is the code im writing)
new_index = offset * direction
where is the error?
All you need to do is multiply the offset
by the direction
in the new_index
assignment. The multiplication operator in Python is *
.
(this is the code im writing)
new_index = offset * direction
where is the error?
Please share the link to the Step and all of the code. Thanks (it is best not to delete the content in the generated post)
Welcome to the forum @claudiodsbastos
Here is a comparison of the original code and your code.
The code in blue is your code, the code in red is the original code.
Where is the rest of the code?
Happy coding
Hi! Here is the full code
text = 'Hello Zaira'
custom_key = 'python'
def vigenere(message, key, direction):
key_index = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in message.lower():
# Append space to the message
if char == ' ':
encrypted_text += char
else:
# Find the right key character to encode
key_char = key[key_index % len(key)]
key_index += 1
# Define the offset and the encrypted letter
offset = alphabet.index(key_char)
index = alphabet.find(char)
new_index = (index + offset) % len(alphabet) -> old code that you mention as red
encrypted_text += alphabet[new_index]
return encrypted_text
#encryption = vigenere(text, custom_key)
#print(encryption)
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
where is direction
now?
Full code back there as it got posted!
Hope it helps
Thanks
I see the code, but where is direction
?
Thats all the code that i got till this step
and what code have you written for this step?
All you need to do is multiply the offset
by the direction
in the new_index
assignment. The multiplication operator in Python is *
.
So im replacing “new_index” variable with this code:
new_index = offset * direction
and as Teller has asked you, where is the rest of that line?
You need to multiply offset
by direction
without removing the rest of your line.
text = 'Hello Zaira'
custom_key = 'python'
def vigenere(message, key, direction):
key_index = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in message.lower():
# Append space to the message
if char == ' ':
encrypted_text += char
else:
# Find the right key character to encode
key_char = key[key_index % len(key)]
key_index += 1
# Define the offset and the encrypted letter
offset = alphabet.index(key_char)
index = alphabet.find(char)
new_index = (index + offset) % len(alphabet)
encrypted_text += alphabet[new_index]
return encrypted_text
#encryption = vigenere(text, custom_key)
#print(encryption)
what do you mean with “rest of that line” ?
This is the full code that I have and step 71 tells me to assign “new_index” variable a different output right?
(really sorry that im not getting it, super new here)
you start with the red line, you wrote the blue line to add direction
, but adding direction
you have removed various other things that give the value to new_index
which you should not remove
It means that you should multiply offset
by direction
without removing what you already have in that line ( which is (index + offset) % len(alphabet)
).
If you have (a + b) / c
and you want to multiply b
by x
, the final result is (a + b*x) / c
That worked!
Makes sense so it still get other things that gave value to new_index.
Thanks all for time and help, really appreciated
– removed by mod –
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.