Tell us what’s happening:
I dont understand where im going wrong, I tried to only rename the variables but i stil dont understand
Your code so far
# User Editable Region
text = 'Hello Zaira'
shift = 3
def caesar(message, offset):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_message = ''
for char in text.lower():
if char == ' ':
encrypted_message += char
else:
index = alphabet.find(char)
new_index = (index + offset) % len(alphabet)
encrypted_message += alphabet[new_index]
print('plain text:', text)
print('encrypted text:', encrypted_text)
caesar()
# 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/120.0.0.0 Safari/537.36 OPR/106.0.0.0
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 49
Teller
January 18, 2024, 10:05pm
2
Welcome to the forum @ali.hzra
ali.hzra:
*text* = 'Hello Zaira'
*shift* = 3
def caesar(message, offset):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_message = ''
for char in text.lower():
if char == ' ':
encrypted_message += char
else:
index = alphabet.find(char)
new_index = (index + offset) % len(alphabet)
encrypted_message += alphabet[new_index]
print('plain text:', text)
print('encrypted text:', encrypted_text)
caesar()
Every instance of text and shift needs to be updated.
I placed asterisks around the first two instances.
The instructions are just asking you to change the variable names. As you code, you may find more meaningful names for code, so will need to change every instance of it to update the code.
Happy coding
Hello ali.hzra,
You forgot to change a few instances such as:
ali.hzra:
for char in text.lower()
Also keep in mind you only need to change text
and shift
, other variables such as encrypted_text
should stay the same.
I can see the following in your code twice, these shouldn’t be renamed.
ali.hzra:
encrypted_message
Hey Teller, this is unfortunately incorrect. Only everything inside the function body needs to be adjusted to match the function signature.
Teller
January 19, 2024, 3:22pm
5
It was mentioned that every instance of the two variables need updating
The questions says “Inside your function body
, rename the text and shift variables to message and offset, respectively.” Hence you dont need to rename anything outside it.
text = 'Hello Zaira'
shift = 3
def caesar(message, offset):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in message.lower():
if char == ' ':
encrypted_text += char
else:
index = alphabet.find(char)
new_index = (index + offset) % len(alphabet)
encrypted_text += alphabet[new_index]
print('plain message:', message)
print('encrypted text:', encrypted_text)
caesar()
this is what I have changed, and I didnt change the variables I wasn’t supposed to, but it still is showing an error message
Teller
January 19, 2024, 4:52pm
8
Hi @ali.hzra
ali.hzra:
print('plain message:',
You seem to have changed a string. Please change it back.
New to Python @HungryBee , still trying to shake JS cobwebs.
1 Like
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 (').
system
Closed
July 20, 2024, 5:30am
10
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.