Learning String Manipulation by Building a Cipher Step 41

In Step 41 here

I got to this point in the process where and I didn’t understand what the assignment was asking me to do. I only got it right because I copied what was in other threads but I don’t understand why its correct.

Why is the “encrypted_text += alphabet [new_index]” correct?:

for char in text.lower():
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text = encrypted_text + alphabet[new_index]
    encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)

Instructions say

Use the += operator to add a value and assign it at the same time to encrypted_text

But it doesn’t specify what value to add so why is alphabet[new_index] correct?

I initially tried

encrypted_text + encrypted_text + alphabet[new_index]
    encrypted_text += encrypted_text

What makes this wrong ?

Please post your actual code instead of a picture. Also, please post a link to the Step. Thanks

edited, does that work?

1 Like

Ok, so this was the original of the line you edited

    encrypted_text = encrypted_text + alphabet[new_index]

The value being appended is given on that line

The value being appended is given on that line

The “value” being alphabet[new_index]?

Yep

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.