Learn String Manipulation by Building a Cipher - Step 19

Tell us what’s happening:

They ask me to do this : Give your for loop a body by adding a call to print(i) . Remember to indent the loop body.
I have no idea of what is wrong with my code… can somebody help ? :pray:

Your code so far


/* User Editable Region */

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
text = lower(text)
for i in text:
    shifted = alphabet[i+shift].find(text(i))
    print(i)
    

/* 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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 19

I don’t think the step wants you to add this line

I deleted it and it still doesn’t work… What does it mean to indent the loop ?

Deleted what? What’s your current code?

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
text = lower(text)
for i in text:
    print(i)

I don’t see any difference, did I miss something ? I left 4 spaces like they said but no luck

that line,

text = lower(text)

isn’t necessary. it’s redefining text into something other than ‘Hello World’

Oh it worked ! But I still don’t understand why it didn’t worked… The text is in lower case and upper case instead of only lower case so why is the output not the same ?

It didn’t work because you changed the values of the text variable.
I’ll give an example: When you create a variable, you can change its value.
So if you created a variable like,

text = ‘apple’

and then somewhere later down you also write

text = ‘oranges’

you’ve just changed what’s contained within the text variable

so if you print text it will print oranges instead of apples because you changed its value.

The original value of text is ‘Hello World’

text = ‘Hello World’

But when you wrote,

text = lower(text)

you changed the original value was from ‘Hello World’ to lower(text)

thus, it won’t print ‘Hello World’

But the challenge wants you to print "Hello World’ by way of a for loop

:slight_smile:

Oh Yes I get it now ! Thank you so much for your help :pray:

1 Like