I'm using Linux Mint 14 (Nadia) and Python 2.7.3. I can't get that 'Cube Root of a Perfect Cube" program working. It prompts me to enter an integer and when I do and hit enter, I go right back to the prompt. Anyone else with this problem?
Did you try tossing in some print statments?
yes e.mccormick is right , to print something on screen you need to insert print statements in your code Going back to the prompt without error means that program executed properly(even tough in this case did not gave the desired result i.e to print the answer)
Thanks a lot. Let me give that a try.
Many programmers will make some sort of console dump or printout to debug things. There are tons of debugging tools, but the basic "print this variable at this instant" method has a serious advantage: It is very easy to do and does not rely on you managing to get the program to stop at just the right moment. I have had a loop print "in loop" at the top just to make sure it was actually looping... found out it was going in, but not looping, traced down the logic error, ran again and got tons of "in loop" messages so I knew that was fixed. Little things like that can be invaluable! So even if you don't print a variable, printing a message would let you know that Python was working.
and also, as Prof Guttag points out in his lecture on debugging, don't just output value for debugging purposes. When you're able (which you should always be) add more to the output to provide context. specifically what variable you're outputting and what you expect it to be. That will make discrepancies jump out at you even more and can save you from your own subliminal assumptions which can take hours to track down in complicated algorithms
and apparently this is an old thread, sorry for the accidental bump
and that one
bah, i give up. back to work
Might as well close it. It is 7 months old. Hehe
Still a good advice, seandisanti
Join our real-time social learning platform and learn together with your friends!