Python Cipher step 16 instructions are not clear enough
Describe the Issue
When working with the Python Cipher at step 16, it mentions the following instructions to complete the challenge:
As you can see from the output,
"h"is at index7in thealphabetstring. Now you need to find the letter at index7plus the value ofshift. For that, you can use the addition operator,+, in the same way you would use it for a mathematical addition.
Declare a variable named
shiftedand assign it thealphabetletter atindexplusshift.
These instructions are not clear enough, as it has popped up multiple times in the forum asking for clarification: https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-16/658948 https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-16/656960 https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-16/658331 https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-16/658121
Affected Page
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-16
Your code
N/A
Expected behavior
The main issue is with the last sentence:
Declare a variable named
shiftedand assign it thealphabetletter atindexplusshift.
In theory, is expected from the user to write the following line of code:
shifted = alphabet[index + shift]
But the wording seems off, I also got confused at first with the instruction. Later in the curriculum a very similar instruction is presented at step 57, but with better wording:
Next, inside the
elseblock, declare a variable calledkey_charand assign it the value ofkeyat the indexkey_indexmod(%) the length ofkey.
Which expects a similar result like above:
key_char = key[key_index % len(key)]
I think wording the step 16 to the following, similar to step 57, would be better:
Declare a variable named
shiftedand assign it the value ofalphabetat the indexindexplusshift.
It does seems redundant to say "at the index index" so it may be necessary to rename the variable. I'm open to suggestions.
Screenshots
No response
System
N/A
Additional context
No response
Hey @juancaorg !
Thank you for raising this issue. I agree that the directions could be updated because like you mentioned it does come up a lot on the forum.
I think wording the step 16 to the following, similar to step 57, would be better:
Declare a variable named shifted and assign it the value of alphabet at the index index plus shift.
It does seems redundant to say "at the index index" so it may be necessary to rename the variable. I'm open to suggestions.
That wording works for me. As for the redundancy, we do mention index twice in the hint text for this step. So repetition might be ok here.
Another change we could make is to the hint text itself and show that index + shift needs to be in brackets
Proposal for updated hint text
You should assign `[index + shift]` to your `shifted` variable.
I have gone ahead and adding the discussing label on it so we can hear from more maintainers about updates to the wording before we open this up for contribution 👍
Some idea is to use alphabet[index] more explicitly in the description. It would work in two ways - remind campers how to use indexing, and it'd be easier to lead them into changing index to index + shift for the solution.
I like how it was worded here, in steps: https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-16/660377/3?u=pkdvalis
If I were to re-word this for the lesson:
Declare a variable called
shiftedand assign it a value which is going to be a letter in thealphabetstring. Use square brackets to access the position of the letter atindex + shift.
This step has generated so many forum posts I would even consider giving a very clear template like: Use the format string[variable1 + variable2]
Declare a variable named
shiftedand assign it the value ofalphabetat the indexpositionplusshift.
Any thoughts on renaming the index variable to position?
Really appreciate everyone's input with this issue! I think using @pkdvalis could be the most clear one:
Declare a variable named
shiftedand assign it a value which is going to be a letter in thealphabetstring. Use square brackets to access the position of the letter atindex + shift.
I think renaming the index variable to position is valid and probably better, but may be unnecessary. I think with the above is good enough.
And for the hint text, instead of the current one:
You should assign the
alphabetletter at the indexindex + shiftto your new variable.
Use the following instead (a combination of @jdwilkin4 and @pkdvalis proposals) :
You should assign the
alphabetletter at the positionindex + shiftto yourshiftedvariable. Use the following format as an example:string[variable1 + variable2].
Let me know what you think.
I don't think it's necessary to modify the name of the index variable. Repetition is perfectly fine here.
To simplify things I would introduce additional steps:
- declare a variable named
shiftedand assign italphabet - modify the assignment into
shifted = alphabet[index] - modify it again into
shifted = alphabet[index + shift]
I like the idea of breaking it up into steps (still within Step 16, right?). The challenge is still to explain the last step in words. In the actual lesson we might word it like this?
- declare a variable named
shiftedand assign it the stringalphabet - modify the assignment into
alphabetat positionindexusing square brackets - modify the position in the square brackets to
index + shift
I have a slight worry that the new learners will get lost adding a line modifying it, and then modifying it again? I don't think this is an approach they will be used to? The leap to adding variables within the square brackets might require this though.
Re: hint text
You should assign the alphabet letter at the position index + shift to your shifted variable. Use the following format as an example: string[variable1 + variable2].
Perfection!
I mean this will be split into 3 (maybe 2) different steps (not in step 16). And not necessarily contiguous steps, since it's better to place the step that is asking to print shift in between.
Agree with this approach.
Maybe we could combine these into 1 step:
- declare a variable named shifted and assign it alphabet
- modify the assignment into shifted = alphabet[index]
Since it should be reinforcing a lesson already introduced in Step 4 https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-4
Without the extra + shift it should be a lot simpler to give and understand the direction.
Thank you soooo much!
Would it help to rename shifted into something more descriptive?
shifted_charnew_charchar_shiftedchar_cipherchar_new
So we can keep in mind that this variable will hold a character, shifted or new in relation to char
I just realized that's exactly what happens in Step 26
Step 26 At the end of your loop body, declare a variable called new_index and assign the value of index + shift to this variable
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-26
Step 26 and 30 break up the exact actions of Step 16 into separate steps
Step 30 Now you need to create a new_char variable at the end of your loop body. Set its value to alphabet[new_index].
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-30
Step 23 Before printing the current character, declare a variable called index and assign the value returned by alphabet.find(char) to this variable.
not clear enough:
Step 23 Before printing the current character, declare a variable called index and assign the value returned by alphabet.find(char) to this variable.
not clear enough:
Step 23 Before printing the current character, declare a variable called index and assign the value returned by alphabet.find(char) to this variable.
This will be changed with the next PR.