I’ve been stuck on Step 49 of the Scientific Computing with Python course for almost two weeks. The step asks me to define a function called caesar() after declaring a shift variable, and indent the following lines to give the function a body.
Here’s my current code:
python
CopyEdit
text = 'Hello Zaira'
shift = 3
def caesar():
alphabet = 'abcdefghijklmnopqrstuvwyz'
encrypted_text = ''
for char in text.lower():
if char == ' ':
encrypted_text += char
eles:
index = alphabet.find(char)
new_index = (index + shift) % len(alphabet)
encryted_text += alphabet[new_index]
print('encrypted text:', encrypted_text)
print('plain text:', text)
caesar()
I’ve tried everything I can think of, but it’s still not working—can someone point out what I’m missing or doing wrong?
I’ve edited your post to improve the readability of the code. 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 edited your post to improve the readability of the code. 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.