Learn String Manipulation by Building a Cipher - Step 14

Tell us what’s happening:

This is my code. I couldnt get the output I knew the answer is 7. I dont understand why the output for me is -1

Your code so far


# User Editable Region

text='Hello world!'
H=text[0]
print(text[0])

alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabet.find('text[0]')
print(alphabet.find('text[0]'))

# 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/130.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 14

The find function looks for the index where the substring you are looking for first appears and if it can’t find the substring then it returns -1. Your code shows that you are looking for the string literal ‘text[0]’ . Your code is literally looking for the string of text ‘text[0]’, and not what I think you want it to find which is the ‘H’, at position/index 0, that calling text[0] without qoutes would get you.

thank you. I passed however still shows -1

1 Like

yep, continue with next step to find out why

1 Like

MOD EDIT: Solution removed.

@sarwatfaizy1908

Hi there and welcome to our community!

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.