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

Thanks to dmancine. I used his advice "Add a bunch of print statements to make sure variables are doing what you think they're doing" to catch the bug. Here's the bug free code: http://dpaste.com/641531/

OpenStudy (anonymous):

If you need some tips for further enhancement on your code, two things I would point out: That else: pass is unnecessary. I used to use it a lot to learn flow of control and stuff like that in Python, but it's really something avoidable. Other thing is that you really don't need to truncate the len(z)/2, as two integers division in Python returns the floor (whether or not this a good thing is really another history). If you are looking for portability, I would use: from __future__ import division and use the new (for Python 3.x) "true division" operator "//". Else, I would avoid truncating in Python 2.x. It's a bit of a useless code, which is not good. Check out this PEP: http://www.python.org/dev/peps/pep-0238/ about division in Python. Overall, your code looks good and kudos for finding a way to solve the palindrome problem. Really liked the functions, I think it's a good programming discipline and makes code more readable/easier to debug (as you may have discovered already). Made some really minor changes to your code: http://codepad.org/vM1RU2Pd Maybe you find something useful.

OpenStudy (anonymous):

or even http://codepad.org/9kHIFqks

OpenStudy (anonymous):

You should be able to do it without global data. You can return values from a function, and pass values into a function. And you don't need to convert the string to a list. They are both "sequences" and the index operator (z[i]) will work the same for both types.

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!