freeCodeCamp icon indicating copy to clipboard operation
freeCodeCamp copied to clipboard

Python Cipher step 16 instructions are not clear enough

Open juancaorg opened this issue 2 years ago • 14 comments

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 index 7 in the alphabet string. Now you need to find the letter at index 7 plus the value of shift. For that, you can use the addition operator, +, in the same way you would use it for a mathematical addition.

Declare a variable named shifted and assign it the alphabet letter at index plus shift.

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 shifted and assign it the alphabet letter at index plus shift.

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 else block, declare a variable called key_char and assign it the value of key at the index key_index mod(%) the length of key.

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 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.

Screenshots

No response

System

N/A

Additional context

No response

juancaorg avatar Dec 29 '23 17:12 juancaorg

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 👍

jdwilkin4 avatar Dec 29 '23 22:12 jdwilkin4

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.

gikf avatar Dec 30 '23 15:12 gikf

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 shifted and assign it a value which is going to be a letter in the alphabet string. Use square brackets to access the position of the letter at index + 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]

pkdvalis avatar Jan 02 '24 17:01 pkdvalis

Declare a variable named shifted and assign it the value of alphabet at the index position plus shift.

Any thoughts on renaming the index variable to position?

pkdvalis avatar Jan 02 '24 17:01 pkdvalis

Really appreciate everyone's input with this issue! I think using @pkdvalis could be the most clear one:

Declare a variable named shifted and assign it a value which is going to be a letter in the alphabet string. Use square brackets to access the position of the letter at index + 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 alphabet letter at the index index + shift to your new variable.

Use the following instead (a combination of @jdwilkin4 and @pkdvalis proposals) :

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].

Let me know what you think.

juancaorg avatar Jan 02 '24 20:01 juancaorg

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 shifted and assign it alphabet
  • modify the assignment into shifted = alphabet[index]
  • modify it again into shifted = alphabet[index + shift]

Dario-DC avatar Jan 02 '24 21:01 Dario-DC

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 shifted and assign it the string alphabet
  • modify the assignment into alphabet at position index using 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!

pkdvalis avatar Jan 02 '24 21:01 pkdvalis

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.

Dario-DC avatar Jan 03 '24 08:01 Dario-DC

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.

pkdvalis avatar Jan 03 '24 16:01 pkdvalis

Thank you soooo much!

luuuuukez avatar Jan 03 '24 17:01 luuuuukez

Would it help to rename shifted into something more descriptive?

  • shifted_char
  • new_char
  • char_shifted
  • char_cipher
  • char_new

So we can keep in mind that this variable will hold a character, shifted or new in relation to char

pkdvalis avatar Jan 04 '24 22:01 pkdvalis

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

pkdvalis avatar Jan 05 '24 19:01 pkdvalis

Step 23 Before printing the current character, declare a variable called index and assign the value returned by alphabet.find(char) to this variable.

ehigt1 avatar Jan 09 '24 00:01 ehigt1

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.

ehigt1 avatar Jan 09 '24 00:01 ehigt1

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.

Dario-DC avatar Jan 09 '24 09:01 Dario-DC