here’s my code so far:
text = 'Hello Zaira'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
if char == ' ':
encrypted_text += char
else:
index = alphabet.find(char)
new_index = (index + shift) % len(alphabet)
encrypted_text += alphabet[new_index]
print('char:', char, 'encrypted text:', encrypted_text)
what to do???
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.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
It’s also helpful to include a link to the challenge (which I have now added for you). In future you can simply click on the Help button, which appears after you have submitted incorrect code three times.
This will create a forum post which automatically includes your full code, a link to the challenge and an opportunity for you to describe your issue in detail.
Next, modify your print()
call to print 'encrypted text:', encrypted_text
and put it outside the for
loop, so that the encrypted string is printed one time.
So, modify this print
call accordingly:
print('char:', char, 'encrypted text:', encrypted_text)
To move it outside of the for
loop, it just needs to have its indentation changed. (It is currently indented into the for
loop, so is part of its body).