Python 3: String Methods: Coded_communications: Step 6

Hi, I need someone’s help to walk me through the Solution for Python 3: String Method: Coded_communications project: Step 6. Screenshot of the Codecademy solution below …

The first line of code defines the function that has been created to take in two arguments. The coded_message which is the jargon of mixed up letters that we’ve been provided with, and the keyword “friends” which we are to apply to the string of mixed up letters. Ok I get that.

The second line of code is kind of like that “counter = 0” which we’ve been seeing a lot of in previous lessons. This letter_pointer (aka counter) helps us keep track of the number of … loops? … that we’re going to cycle through. The total number of loops is determined by fourth line of code and the lowercase letter i helps us to find the placement (which letter we’re currently at) in the string of mixed up letters.

My first question is, what is the third line of code for? Why do we need to know the final keyword. I thought we were given the keyword. It’s “friends.” ??

I guess they use the keyword_final to make a string of the keyword (repeated as necessary) that’s the same length as coded_message.
The purpose of the first for-loop seems to be to create this keyword_final string,
by adding one letter from keyword to keyword_final for each letter in coded_message
keyword_final = '' has to be before the loop so that there’s a string to add those letters to.

And letter_pointer keeps track of which letter you’re on (or your position in the string)
0 for the first letter
1 for the second letter
and so on.
(Yes, letter_pointer is a counter for the letters.)

So "I am not the president." (where the number of letters is 18) as coded_message
would have "friendsfriendsfrie" (length 18) as keyword_final
if "friends" is the keyword.

 

Next time, please post the code using the </> button and put the code on lines between the ``` and ```
instead of using a screenshot.