Tell us what’s happening:
so my problem is that idk how to put the print(‘space!’) bc for some reason its not letting it
btw the intructions: At the top of your for loop, replace print(char == ' ')
with an if
statement. The condition of this if
statement should evaluate to True
if char
is an empty space and False
otherwise. Inside the if
body, print the string 'space!'
. Remember to indent this line.
Your code so far
# User Editable Region
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
if char == ' ':print('space!')
print("True")
else:
print("False")
print('space!')
index = alphabet.find(char)
new_index = index + shift
encrypted_text += alphabet[new_index]
print('char:', char, 'encrypted text:', encrypted_text)
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 41
Hi @Program_Parker,
Bring the first print statement print('space!')
under your if statement and indent it. You can then remove the other print statements and else code that was added. Hope this helps. Happy coding!
for char in text.lower():
if char == ’ ':
print(‘space!’)
print(“True”)
index = alphabet.find(char)
new_index = index + shift
encrypted_text += alphabet[new_index]
print(‘char:’, char, ‘encrypted text:’, encrypted_text)
this is how it looks like now and what does it mean indent?
Indention (preceding spaces) is what Python expects for any code within a code block, like a for loop or if statement.
For example:
for list in lists:
print(list)
if list === null:
break
else:
continue
The spaces before the lines of code within the for loop are the indentions. So you’ll want to indent the code you just shared that is within the for loop, and indent the code within the if statement as well.
I hope this helps. Happy coding!
eventhough i edited it its still not accepting it maybe my problem is somewhere else
Remove the print("True")
statement.
it’s still not working, perhaps something else too?
Please share your code if/when you update it.
it says indentation error: unindent does not match any outer indentation level
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
if char == ' ':
print('space')
index = alphabet.find(char)
new_index = index + shift
encrypted_text += alphabet[new_index]
print('char:', char, 'encrypted text:', encrypted_text)
You will need indention for everything within your for-loop, as well as everything within your if statements. Double-check that there is an exclamation point (!) within your first print statement print('space!')
.
yeah somehow dissapeared but put it back,still the same error
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 (').
thank you that’s very nice of you
I’m still kinda puzzled on where i went wrong
the error is said to be on line 9
Your code should look similar to the following pattern for indention: (the periods in the example will match one space)
variable
variable
variable
variable
for loop:
..if statement:
....print
..variable
..variable
..variable
..print
that is how it is, also i finally got the output but it isn’t accepting it
at my code it is i fixed it
somehow i get the correct output but it won’t accept it