I'm writing a lesson on debugging for my students. They will have already had a lesson on how to read code and do walkthroughs, either manually or using the debugger. They currently know about if, while, types, math operators, and have some experience with but no formal training in functions and methods. (We're finishing ch. 3 of Dawson's Python Programming for the Absolute Beginner).

So the lesson on debugging will emphasize verifying that the code does what it looks like it should do. In addition, we'll discuss common errors (bad indentation; naming a function instead of calling it; off-by-one; infinite loops; etc.).

So: what Python errors cause you fits? Or, do you have any hair-pulling stories to share? Or, do you have any "I had to debug someone else's code and it was a stupid ___ error" stories?

Thanks,
Jeff

Even though Python has // as an integer division operator, I most commonly use the / operator. Right now you can use the / or the // operator for integer divisions, and here is were I get into trouble.

a = 4/5
print a  # oops the result is 0 and I wanted 0.8

This will change with Python30, there you have to use // for integer division or you will get float division.

Another of my common errors is mismatching the numbers of () or [].

So the lesson on debugging will emphasize verifying that the code does what it looks like it should do. In addition, we'll discuss common errors (bad indentation; naming a function instead of calling it; off-by-one; infinite loops; etc.).

Okay, i dont know anything about python(Im a VB guy) but in VB its always interesting to give someone a equasion which works if they do it by themselves in thier head, but not on the computer, due to operator precedence (BODMAS)


(B)rackets
(O)rder (sometimes called (I)ndicies)
(D)ivision
(M)ultiplication
(A)ddition
(S)ubtraction

e.g

What do you think the answer to 2 + 3 x 5 is?

Is it (2 + 3) x 5 = 5 x 5 = 25 ?

or 2 + (3 x 5) = 2 + 15 = 17 ?

(its actually 17!!)!

>>> from __future__ import braces
  File "<stdin>", line 1
SyntaxError: not a chance

Haha! Favorite error ever! All versions of python have this "hidden feature." It's obviously making fun at C. : P

>>> from __future__ import braces
  File "<stdin>", line 1
SyntaxError: not a chance

Haha! Favorite error ever! All versions of python have this "hidden feature." It's obviously making fun at C. : P

A very funny discovery, thank you!

I laughed out loud! Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.