CMPT 120 Lecture : Debugging
meghan78 and 39786 others unlocked
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
What you have typed isn"t legal python code. Common errors: eg. bad indentation if x==0: print print, mismatched quotes/brackets, eg. print hello world" x = 1+(y-z*len(s) = vs. =: runtime errors eg. while the program is running, it hits something it can"t handle print x x=int(raw_input()) y = 0 x=10/y. Zerodivisionerror it is possible to handle these errors gracefully in the program (later: semantic errors. The program runs, but doesn"t do what you expect. The hardest to fix: no error message to work with, many possibilities for the cause, could be an incorrect algorithm, or incorrect translation of algorithm to code. You have to figure out what in your program differs from your expectations. First strategy: test as you go: write your program in small steps, use the print statement to check that your code does what. Test each new addition as you make it you expect: print variable values, value of loop condition, etc.