otb125
December 16, 2024, 3:14pm
1
Tell us what’s happening:
what am im doing wrong, i forgot how to make indention
thanks
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
December 16, 2024, 3:15pm
2
to indent add spaces at the beginning of the line, you still need to indent the for loop and the print statements
otb125
December 16, 2024, 3:23pm
3
otb125:
def caesar():
sorry, how should i indent the for loop and print?
not to sure about the spacing for the code
strong text
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)
.
ILM
December 16, 2024, 3:23pm
4
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 (').
1 Like
ILM
December 16, 2024, 3:24pm
5
the for
should be at the same level of encrypted_text
, while the content of the loop should be indented 4 spaces more than that
ILM
December 16, 2024, 3:25pm
6
alternatively, reset the step, add the function defition, then select everything that should go inside the function and press the tab key once
otb125
December 16, 2024, 3:32pm
7
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)
hi, im still having trouble…
ILM
December 16, 2024, 3:32pm
8
the two prints go inside the function too
1 Like