Scientific Computing with Python - Step 37

in this step, the codes are:

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''

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

The name before encrypted_text was new_char, why is it necessary to changethe variable name into encrypted_text?

encrypted_text is a clearer name that better holds what that variable holds. new_char implies the variable only holds a single character (like a letter) and it is pretty vague.

1 Like