I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
I’ve been working on the Caesar cipher, but I’m still unable to pass the test on FreeCodeCamp. My code is below, and I’ve checked the output carefully to make sure there’s no extra spacing. However, it still isn’t passing.
text = 'Hello Zaira'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text:
if char == ' ':
encrypted_text += char
else:
index = alphabet.find(char.lower())
new_index = (index + shift) % len(alphabet)
new_char = alphabet[new_index]
if char.isupper():
encrypted_text += new_char.upper()
else:
encrypted_text += new_char
print('Plain text:', text)
print('Encrypted text:', encrypted_text)
out put: Plain text: Hello Zaira
Encrypted text: Khoor Cdlud