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

I'm working on the very first iterative problem in PS03. I'm not sure if what I've started is remotely close to what it should be, but here's my code nonetheless: http://dpaste.com/590997/ Useful answers much appreciated. Getting "it's just wrong" with a snippet of code and no explanation is not helpful to me.

OpenStudy (anonymous):

The big problem... your for loop isn't going to iterate. The return statement on line 8 is going to hit on your first time through the loop... returning either 1 or 0 (when the find function returns 0 or -1); and the function will end. Even clearing that hurdle doesn't help much: you're iterating over each character in your target string (for s in target), but you're not using the change to alter the test conditions... so if you ran through the sequence, you'd either get a result of 0 (key not found) or len(target) -- the number of characters in the target string (because you increased the counter every time through the loop). To compare.... http://dpaste.com/591132/

OpenStudy (anonymous):

Thanks! This has helped out a lot.

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!