Tell us what’s happening:
There is a name error on line 14… Where it says encrypted_text is not defined. Ive tried to correct but it wont change anything…
Your code so far
# User Editable Region
text = 'Hello Zaira'
shift = 3
def caesar():
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('plain text:', text)
print('encrypted text:', encrypted_text)
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 49
ILM
January 16, 2025, 7:30am
2
this print
is outside the function, encrypted_text
exists only inside the function
what were you asked to do with the two print statements?
1 Like
Right after your shift
variable, declare a function called caesar
and indent all the following lines to give your new function a body.
Once that was done it required everything that was under the shift=3 variable be indented and now it wont work no matt
er what i do…
ILM
January 16, 2025, 7:49am
4
and did you indent all of the lines? all of them?
def caesar():
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('plain text:', text)
print('encrypted text:', encrypted_text)
After i was advised to put all the outside variables into the new function or change them into parameters and am still stuck
ILM
January 16, 2025, 7:51am
6
follow the step instructions only
where the two print statements inside the else
before creating the function?
idk how to do it and i think i did… Mde sure where a required indent was needed after the colon was indented and still dont know…
no they were not… the initial problem wanted them inside so i did it and now its the indent problem…
ILM
January 16, 2025, 7:53am
9
inside what? the else
? or only the function?
ILM
January 16, 2025, 7:54am
10
to put things inside the function you needed to indent only 4 spaces, the print
statements are indented 12 spaces more than they were before, that’s a great change
2 Likes
the function i think… (…)
ILM
January 16, 2025, 7:57am
12
what are you going to do now?
Thank you it worked finally…
I deleted the extra indents until the prints were at the end of the for loop