Learn String Manipulation by Building a Cipher - Step 23

Tell us what’s happening:

Having a difficult time understanding. I tried just about everything.

Your code so far

text = ‘Hello World’

shift = 3

alphabet = ‘abcdefghijklmnopqrstuvwxyz’

index = text(char)

for char in text:

print(char)


/* User Editable Region */

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = text(char)
for char in text:
    print(char)
    
    

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

char doesn’t exist outside the loop, where does it exist?

The clues are in the instructions:

a) Before printing the current character
(so gives a clue as to where you need to create this line of code)

b) declare a variable called index
(declare means to basically create a variable)
Ex. iamavariable =

c) and assign the value returned by alphabet.find(char) to this variable.
(here, the .find function is finding the integer value in the index of the alphabet variable that corresponds to each char (character) of ‘Hello World’ presented to it within the parenthesis. Thus alphabet.find(char) will always return a value, an integer value,
so this line of code basically represents a value.)

And the instruction is to declare a variable called index and then assign a value to it.

Sidenote: char is a placeholder for any character in the text variable for the loop. If it is written outside of a for loop, it won’t mean anything.

Hope this helps.

2 Likes

You are the best, thank you so much

1 Like