Jun-18-2018, 07:58 AM
The code you have written has almost all the correct elements, but it doesn't work for a few reasons:
1. 'lettersToFind' is a tuple and not a single letter. Ever. So your comparison condition always fails. But Python does provide a dead easy way of fixing this. Since 'lettersToFind' is a tuple, every time you need to check if the letter under consideration is 'in' this data container.
So change line 6 to
So change line 6 to
I hope this helped.
1. 'lettersToFind' is a tuple and not a single letter. Ever. So your comparison condition always fails. But Python does provide a dead easy way of fixing this. Since 'lettersToFind' is a tuple, every time you need to check if the letter under consideration is 'in' this data container.
So change line 6 to
if sentence[INDEX] in lettersToFind:2. The characters in 'Hello World' are of different font cases. For example, if you were to run your code, it would say that 'L' is not found in sentence. That is because it isn't in your sentence. The lowercase version of it is.
So change line 6 to
if sentence[INDEX].upper() in lettersToFind:3. With 1 and 2, your code will run fine. It's just that the places you are printing out 'lettersToFind' cause me pain. Inside the loop, if found, just print out sentence[INDEX] and its position.
I hope this helped.