Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 13 Online
OpenStudy (anonymous):

In PS4 problem 3 I started out with this: count = 0 while count < len(shifts): for char in text: location = shifts[count][0] if text.index(char) >= location: but when I run it, it says substring not found for location in my if statement. However, if I simply print location it does so with no problems. Why is it not able to find it then in the conditional?

OpenStudy (puzzler7):

This means that in text.index(char), char was not in text, and so it raised an exception.

OpenStudy (puzzler7):

text.index(char) searches for char in text. If char is in text, it returns that index. Else, it raises an error.

OpenStudy (anonymous):

Ok thank you, I switched it to text.find(char). I thought that text.index would work because I was inside a for loop for char in text, so I thought all of the char would be found

OpenStudy (puzzler7):

Welcome.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!