for char in text.lower():
index = alphabet.find(char)
new_index = (index + shift)
# new_char = alphabet[new_index]
# encrypted_text += new_char
encrypted_text += alphabet[new_index]
print(‘char:’, char, ‘encrypted_text:’,encrypted_text)
# User Editable Region
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, 'encrypted_text:', encrypted_text)
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 34
There’s two things here, a string which is just text describing what’s being printed
‘encrypted_text:’
and the variable being printed:
encrypted_text
The variable has an underscore because you can’t have spaces in a variable and it’s two words, it just makes it easier to read. You also have to reference a variable by it’s exact name, you can’t change it.
The text could be anything you want, and we don’t usually_write_spaces_as_underscores
‘This is the variable named “encrypted_text”:’
‘Encrypted Message:’
You might write something like that to describe it. If you wanted you could write encrypted_text as well, if you wanted, just not for this test. It’s a bit arbitrary.