Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+7 votes

Any tips on how to fix my code so that it skips words in the message where the index is invalid? My code works for the first test example in moodle so I know it's close, but when I try to test the second example it gets part of the way through (to the -9) and then sends the IndexError message.

asked in old_CSC201 by (1 point)

1 Answer

+1 vote

The first test case has all valid indexes so if you pass the first test, you've understood how to extract the letters for the secret message as long as the index in the numbers list is valid.

The test cases have both valid and invalid indexes that are both positive and negative. You need to make sure the index is valid before you try to use it to access the letter so that you won't have an IndexError.

So when is the index valid? It depends on the word you are trying to index. There is a certain range of indices from a particular negative integer to a particular positive integer that are valid for each word. You need to figure out that valid range.

answered by (1 point)
...