Learn String Manipulation by Building a Cipher - Step 25

Tell us what’s happening:

find is again returning -1 for uppercase letters, and for the space character, too. You are going to take care of the space later on.

For now, instead of iterating over text, change the for loop to iterate over text.lower().

Your code so far


/* User Editable Region */

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


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

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hello! @ssdaymanq005

In the code you’ve provided, The letter ‘H’ and ‘W’ are in Uppercase. So, it is returning the index as -1. To avoid this we are using the lower() function in the creation of the ‘for loop’.

If you are still stuck, here is a hint on how to add the lower() function:

Hint
for letter in word.lower():

Happy Coding :slight_smile:

/* User Editable Region */

text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
for char in text.lower():
index = alphabet.find(char)
print(char, index)

/* User Editable Region */